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

NoSuchMethodException when the return value of a function in a structural refinement on Any is a parameter #9919

Open
scabug opened this issue Sep 9, 2016 · 3 comments
Milestone

Comments

@scabug
Copy link

scabug commented Sep 9, 2016

The following code:

import scala.language.reflectiveCalls
def double[T](x: Any{def * (arg0: Int): T}) = x * 2
double[Int](4)

causes the following exception:

java.lang.NoSuchMethodException: java.lang.Integer.$times(int)
  at java.lang.Class.getMethod(Class.java:1778)
  at .reflMethod$Method1(<console>:18)
  at .double(<console>:18)
  ... 32 elided

However, it works as expected when I change the definition of double to:

def double(x: Any{def * (arg0: Int): Int}) = x * 2

scala> double(4)
res21: Int = 8
@scabug
Copy link
Author

scabug commented Sep 9, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9919?orig=1
Reporter: Michał Kosek (michau)
Affected Versions: 2.11.8

@scabug
Copy link
Author

scabug commented Sep 13, 2016

@SethTisue said (edited on Sep 13, 2016 8:34:06 PM UTC):
note that structural types are AnyRef by default so an explicit "Any { ... }" is required here

@scabug
Copy link
Author

scabug commented Feb 11, 2017

@SethTisue said:
#10175 has reproduction code that doesn't involve a type parameter:

val oops: Any { def +(a: Int): Any } = 42
import scala.language.reflectiveCalls
oops + 5

java.lang.NoSuchMethodException: java.lang.Integer.$plus(int)

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