-
Notifications
You must be signed in to change notification settings - Fork 21
Structural types which specify concrete versions of generic methods can lead to runtime failures #2672
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-2672?orig=1 |
@dubochet said: |
@dubochet said: class C[+T](val x: { var y : T })
object A extends C[Int](new { var y = 1 })
(A:C[Any]).x.y = "" java.lang.NoSuchMethodException: A$$$$anon$$1.y_$$eq(java.lang.Object) |
Erik Bruchez (ebruchez) said: Related StackOverflow question: |
@paulp said: |
@lrytz said: val o = new {
def f(x: Object) = new {
def g(y: x.type) = 0
}
}
val s = ""
o.f(s).g(s) |
@paulp said: Actually that's a bug, and then there's also a bug that it's generating a call to a (String)Unit method. Where def g is declared x is an Object - I wonder how it's even getting its hands on "String"... |
@lrytz said: What should be disallowed? I think the code makes perfect sense, and the type checker is able to handle it correctly. Only it crashes at run-time. scala> val o = new {
| def f(x: Object) = new {
| def g(y: x.type) = 0
| }
| }
o: Object{def f(x: Object): Object{def g(y: x.type): Int}} = $anon$1@7471c619
scala> val s = ""
s: String = ""
scala> val o1 = o.f(s)
warning: there were 1 feature warnings; re-run with -feature for details
o1: Object{def g(y: s.type): Int} = $anon$1$$anon$2@2a11890d
scala> o1.g("huh")
<console>:11: error: type mismatch;
found : String("huh")
required: s.type
o1.g("huh")
^
scala> o1.g(s)
warning: there were 1 feature warnings; re-run with -feature for details
java.lang.NoSuchMethodException: $anon$1$$anon$2.g(java.lang.String)
at java.lang.Class.getMethod(Class.java:1605)
at .reflMethod$Method1(<console>:11)
[...] |
@paulp said: |
Still broken in Scala 3.0.0:
Good that it requires an import, but I don't consider |
But not broken anymore in Scala 3 nightlies :) 15 | fail(new MyGraph[Int])
| ^^^^^^^^^^^^^^^^
| Found: Test.MyGraph[Int]
| Required: Test.DuckGraph |
This is extracted from the later comments of ticket #2144, which was otherwise addressed.
The text was updated successfully, but these errors were encountered: