Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-10175

Structural types + value types + method subtyping = NoSuchMethodException

    Details

    • Type: Bug
    • Status: CLOSED
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: Scala 2.12.1
    • Fix Version/s: None
    • Component/s: Compiler (Misc)
    • Labels:
      None

      Description

      scala> val oops: Any { def +(a: Int): Any } = 42
      oops: Any{def +(a: Int): Any} = 42
      

      This works because Int has a method def +(a: Int): Int and Int <: Any.
      But when you try to use it, you get a NoSuchMethodException:

      scala> import scala.language.reflectiveCalls
      import scala.language.reflectiveCalls
       
      scala> oops + 5
      java.lang.NoSuchMethodException: java.lang.Integer.$plus(int)
        at java.lang.Class.getMethod(Class.java:1786)
        at .reflMethod$Method1(<console>:14)
        ... 39 elided
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                Jasper-M Jasper-M
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: