Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implicit generic value class causes compilation error #8018

Closed
scabug opened this issue Nov 29, 2013 · 2 comments
Closed

implicit generic value class causes compilation error #8018

scabug opened this issue Nov 29, 2013 · 2 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Nov 29, 2013

This code does not compile:

object Test {

  sealed trait Parser[I]

  implicit class ParserOps[I](val parser: Parser[I]) extends AnyVal {

    def trans(pf: PartialFunction[Parser[I], Parser[I]]): Parser[I] = {
      parser
    }

    def withErrorValue(errorValue: => Parser[I]): Parser[I] = parser trans {
      case p => p
    }

  }

}

The error is:

overriding method applyOrElse in trait PartialFunction of type [A1 <: eu.swdev.parser.push.Test.Parser[I], B1 >: eu.swdev.parser.push.Test.Parser[I]](x: A1, default: A1 => B1)B1;
 method applyOrElse has incompatible type
    def withErrorValue(errorValue: => Parser[I]): Parser[I] = parser trans {
object creation impossible, since method isDefinedAt in trait PartialFunction of type (x: eu.swdev.parser.push.Test.Parser[I])Boolean is not defined
(Note that A does not match eu.swdev.parser.push.Test.Parser[I])
    def withErrorValue(errorValue: => Parser[I]): Parser[I] = parser trans {
                                                                           ^                                                                           ^

The compilation error disappears if

  • the ParserOps class is changed such that it does not extend
    AnyVal or
  • the type parameter I is removed from the Parser class
@scabug
Copy link
Author

scabug commented Nov 29, 2013

Imported From: https://issues.scala-lang.org/browse/SI-8018?orig=1
Reporter: stefan.wachter-at-gmx.de
Duplicates #8011

@scabug scabug closed this as completed Nov 29, 2013
@scabug
Copy link
Author

scabug commented Nov 29, 2013

@retronym said:
Duplicate of #8011, fixed in 2.11.0-M8.

Fixed in scala/scala@cb37548

scalac-hash cb37548ef85d471951867b9f8a97cb9b9820fc66 sandbox/test.scala
(remotes/origin/2.10.2) ~/code/scala2 scalac-hash cb37548ef85d471951867b9f8a97cb9b9820fc66~1 sandbox/test.scala
sandbox/test.scala:11: error: overriding method applyOrElse in trait PartialFunction of type [A1 <: Test.Parser[I], B1 >: Test.Parser[I]](x: A1, default: A1 => B1)B1;
 method applyOrElse has incompatible type
    def withErrorValue(errorValue: => Parser[I]): Parser[I] = parser trans {
                                                                           ^
one error found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants