bug
bug copied to clipboard
crash as local trait's reference to sibling local is mixed in to subclass with same reference
[nix-shell:/code/scala/sandbox]$ cat Test.scala
class Q {{
object F { def apply(): Int = 1 }
trait L { def x = F() }
class X() extends L { def y = F() }
println(new X())
}}
[nix-shell:/code/scala/sandbox]$ scala -d . Test.scala
[nix-shell:/code/scala/sandbox]$ javap -p Q\$X\$1.class
Compiled from "Test.scala"
public class Q$X$1 implements Q$L$1 {
private final Q $outer;
private final scala.runtime.LazyRef F$module$1;
private final scala.runtime.LazyRef F$module$1;
public void Q$L$1$_setter_$F$module$1_$eq(scala.runtime.LazyRef);
public scala.runtime.LazyRef F$module$1();
public int x();
public int y();
public Q Q$L$$$outer();
public Q$X$1(Q, scala.runtime.LazyRef);
}
Ref: https://gitter.im/scala/scala?at=5db028439825bd6bacb2971b
OK, it's even easier than I thought:
class Test {{
val a = new AnyRef
trait L { def x = a }
class X() extends L { def y = a }
new X()
}}
@hrhino Any idea how I can work around this at least for a moment?
In your case, you can wrap your code in an object and then evaluate the object. I'm not sure why you need the braces in worksheet mode. Alternatively, you could declare the classes/traits outside of the braces so they wouldn't need to be lambdalifted.