Closed scabug closed 8 years ago
Imported From: https://issues.scala-lang.org/browse/SI-967?orig=1 Reporter: Geoffrey Alan Washburn (washburn)
@odersky said: Milestone next_bugfix deleted
@dubochet said: I now understand why this is a problem. Unfortunately, without runtime types (or manifests) this bug cannot be fixed in another way than to have the compiler reject that code.
More precisely --- take a deep breath at that point ---, the compiler must reject method calls on structural types that contain methods in which a parameter is defined as a type member of the structural type.
I'll implement that test when I have time.
@dubochet said: Fixed in r19442.
@milessabin said: I'm going to raise this from the dead, because a very minor variation on Geoffrey's original example fails in exactly the same way. This isn't a regression in 2.10 ... I don't think the problem was ever properly fixed.
scala> import scala.language.reflectiveCalls
import scala.language.reflectiveCalls
scala> type Nat = { type T; val z: T; def s()(arg: T): T }
defined type alias Nat
scala> val nat : Nat = new { type T = Int; val z = 0; def s()(arg:Int) = arg + 1 }
nat: Nat = $anon$1@4a2ead0a
scala> nat.z
res0: nat.T = 0
scala> nat.s()(nat.z)
java.lang.NoSuchMethodException: $anon$1.s(java.lang.Object)
at java.lang.Class.getMethod(Class.java:1622)
at .reflMethod$Method1(<console>:11)
at .<init>(<console>:11)
at .<clinit>(<console>:11)
at .<init>(<console>:7)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:731)
at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:980)
at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:570)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:601)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:565)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:745)
at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:790)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:702)
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:566)
at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:573)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:576)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:867)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:822)
at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:822)
at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:822)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:83)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:105)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
@paulp said: See also #5378, which I never got back to somehow. There are probably a whole bunch of variations on this available given the ad hoc manner in which it is recognized.
@JamesIry said: 2.10.2 is about to be cut. Kicking down the road and un-assigning to foster work stealing.
Olivier Blanvillain (OlivierBlanvillain) said:
I think this can be closed, scalac now properly rejects the Nat
type in Miles comments with an error: Parameter type in structural refinement may not refer to a type member of that refinement
.
While trying to simulate SML: