Scala Programming Language
  1. Scala Programming Language
  2. SI-8011

"object creation impossible" despite exact signature match

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0
    • Fix Version/s: Scala 2.11.0-M8
    • Component/s: Misc Compiler
    • Labels:
      None

      Description

      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.

        Issue Links

          Activity

          Hide
          Jason Zaugg added a comment -

          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: https://github.com/scala/scala/pull/3195

          Show
          Jason Zaugg added a comment - 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: https://github.com/scala/scala/pull/3195
          Hide
          Paul Phillips added a comment -

          Man, my trunk build is four days old.

          Show
          Paul Phillips added a comment - Man, my trunk build is four days old.

            People

            • Assignee:
              Jason Zaugg
              Reporter:
              Paul Phillips
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development