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

"object creation impossible" despite exact signature match #8011

Closed
scabug opened this issue Nov 26, 2013 · 3 comments
Closed

"object creation impossible" despite exact signature match #8011

scabug opened this issue Nov 26, 2013 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Nov 26, 2013

You'd be hard pressed to reason your way to why this doesn't compile.

object Thing {
  implicit class ThingOps1(val x: String) extends AnyVal {
    def fn[A] : Ordering[A] = new Ordering[A] {
      def compare(x1: A, x2: A): Int = ???
    }
  }
  implicit class ThingOps2[A](val x: String) extends AnyVal {
    def fn: Ordering[A] = new Ordering[A] {
      def compare(x1: A, x2: A): Int = ???
    }
  }
}
// a.scala:3: error: object creation impossible, since method compare
// in trait Ordering of type (x: A, y: A)Int is not defined
//     def fn[A] : Ordering[A] = new Ordering[A] {
//                                   ^
// a.scala:8: error: object creation impossible, since method compare
// in trait Ordering of type (x: A, y: A)Int is not defined
//     def fn: Ordering[A] = new Ordering[A] {
//                               ^
// two errors found

Remove the "extends AnyVals" and both compile. It's specific to generics:. This compiles:

implicit class ThingOps1(val x: String) extends AnyVal {
  def fn: Ordering[Boolean] = new Ordering[Boolean] {
    def compare(x1: Boolean, x2: Boolean): Int = ???
  }
}

As a workaround you can do something like

  class Ord[A](f: (A, A) => Int) extends Ordering[A] { 
    def compare(x1: A, x2: A): Int = f(x1, x2)
  }
  implicit class ThingOps1(val x: String) extends AnyVal {
    def fn[A] : Ordering[A] = new Ord[A]((x1, x2) => ???)
  }

How this has not yet been reported I don't know.

@scabug
Copy link
Author

scabug commented Nov 26, 2013

Imported From: https://issues.scala-lang.org/browse/SI-8011?orig=1
Reporter: @paulp
Affected Versions: 2.10.0

@scabug
Copy link
Author

scabug commented Nov 26, 2013

@retronym said:
This one was fixed a few days back in cb37548ef85d471951867b9f8a97cb9b9820fc66. While peforming some housework in Uncurry, I found that we weren't substituting symbols in ClassInfoType#parents. I included a test case in that commit that showed the same bug in extension methods (with partial functions).

I've submitted your test case: scala/scala#3195

@scabug
Copy link
Author

scabug commented Nov 26, 2013

@paulp said:
Man, my trunk build is four days old.

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

No branches or pull requests

2 participants