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

incorrect owner printed after failed, overloaded scope lookup

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: Scala 2.11.0-M1
    • Fix Version/s: Scala 2.11.0-M8
    • Component/s: Type Checker
    • Labels:
      None

      Description

      Regressed in https://github.com/scala/scala/pull/1554

      scalac-hash 3d248efcc~1 test.scala
      topic/2.11-compat ~/code/spire scalac-hash 3d248efcc test.scala
      test.scala:13: error: reference to sqrt is ambiguous;
      it is both defined in object FastComplex and imported subsequently by
      import java.lang.Math.sqrt
        sqrt(0d)
        ^
      one error found
      
      package p
      
      trait NRoot[A]
      
      object `package` {
        final def sqrt(x: Double): Double = Math.sqrt(x)
        final def sqrt[A](a: A)(implicit ev: NRoot[A]): A = ???
      }
      
      object FastComplex {
        import java.lang.Math.sqrt
      
        sqrt(0d)
      }
      

      As seen in Spire: https://github.com/retronym/spire/tree/topic/2.11-compat

        Activity

        Hide
        Jason Zaugg added a comment -

        /cc, just FYI, to Erik Osheim

        Show
        Jason Zaugg added a comment - /cc, just FYI, to Erik Osheim
        Hide
        Jason Zaugg added a comment -

        Actually, this looks like a progression, it is now consistent with a non-overloaded method in a package object and an example with nesting:

        // Fails uniformly on 2.10 and 2.11
        object Enc {
          def sqrt(x: Double): Double = Math.sqrt(x)
          def sqrt(x: String): Double = Math.sqrt(0)
          object FastComplex {
            import java.lang.Math.sqrt
        
            sqrt(0d)
          }
        }
        
        Show
        Jason Zaugg added a comment - Actually, this looks like a progression, it is now consistent with a non-overloaded method in a package object and an example with nesting: // Fails uniformly on 2.10 and 2.11 object Enc { def sqrt(x: Double): Double = Math.sqrt(x) def sqrt(x: String): Double = Math.sqrt(0) object FastComplex { import java.lang.Math.sqrt sqrt(0d) } }
        Hide
        Jason Zaugg added a comment -

        ... but at least the error message is wrong: "is both defined in object FastComplex". When I debugged, I saw that the method defined in the package object had somehow become owned by the module class `FastComplex`!

        Show
        Jason Zaugg added a comment - ... but at least the error message is wrong: "is both defined in object FastComplex". When I debugged, I saw that the method defined in the package object had somehow become owned by the module class `FastComplex`!
        Hide
        Jason Zaugg added a comment -

        Oh, it was overloaded, and calling `OverloadedSymbol#owner` isn't such a great idea: one must look at the owners of the alternatives.

        Show
        Jason Zaugg added a comment - Oh, it was overloaded, and calling `OverloadedSymbol#owner` isn't such a great idea: one must look at the owners of the alternatives.
        Show
        Jason Zaugg added a comment - https://github.com/retronym/scala/tree/ticket/8024
        Show
        Jason Zaugg added a comment - https://github.com/scala/scala/pull/3214

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development