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

crash as local trait's reference to sibling local is mixed in to subclass with same reference #11777

Open
hrhino opened this issue Oct 23, 2019 · 4 comments
Assignees
Milestone

Comments

@hrhino
Copy link
Member

@hrhino hrhino commented Oct 23, 2019

[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);
}
@hrhino hrhino added this to the Backlog milestone Oct 23, 2019
@hrhino hrhino self-assigned this Oct 23, 2019
@hrhino

This comment has been minimized.

Copy link
Member Author

@hrhino hrhino commented Oct 23, 2019

@hrhino

This comment has been minimized.

Copy link
Member Author

@hrhino hrhino commented Oct 24, 2019

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 hrhino changed the title crash as local trait's reference to sibling module is mixed in to subclass with same crash as local trait's reference to sibling local is mixed in to subclass with same reference Oct 24, 2019
@lukasz-gosiewski

This comment has been minimized.

Copy link

@lukasz-gosiewski lukasz-gosiewski commented Oct 25, 2019

@hrhino Any idea how I can work around this at least for a moment?

@hrhino

This comment has been minimized.

Copy link
Member Author

@hrhino hrhino commented Oct 25, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.