You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@retronym said:
Here's a closely related problem in the batch compiler. The reference to a private case class parameter in the synthetic unapply method uses the case accessor if defined after the case class, but directly uses the private accessor (which is duly made nonPRIVATE with an expanded name) otherwise.
The order of typechecking matters for interactions with the per-run map renamedCaseAccessors
% cat test/files/presentation/private-case-class-members/src/State.scala
object State
case class State(private val foo: Int)
case class State2(private val foo: Int)
object State2
object Test {
def main(args: Array[String]): Unit = {
State.unapply(new State(42))
}
}
ticket/8941 ~/code/scala (qscalac test/files/presentation/private-case-class-members/src/State.scala 2>&1) && for i in State State2; do echo ':javap -verbose '$i'$#unapply' | qscala; done; stty echo
Welcome to Scala version 2.11.5-20141028-192350-8f9e9c8938 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_65).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :javap -verbose State$#unapply
public scala.Option unapply(State);
Code:
Stack=3, Locals=2, Args_size=2
0: aload_1
1: ifnonnull 10
4: getstatic #31; //Field scala/None$.MODULE$:Lscala/None$;
7: goto 24
10: new #33; //class scala/Some
13: dup
14: aload_1
15: invokevirtual #37; //Method State.State$$foo:()I
18: invokestatic #43; //Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer;
21: invokespecial #46; //Method scala/Some."<init>":(Ljava/lang/Object;)V
24: areturn
LocalVariableTable:
Start Length Slot Name Signature
0 25 0 this LState$;
0 25 1 x$0 LState;
scala> :quit
Welcome to Scala version 2.11.5-20141028-192350-8f9e9c8938 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_65).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :javap -verbose State2$#unapply
public scala.Option unapply(State2);
Code:
Stack=3, Locals=2, Args_size=2
0: aload_1
1: ifnonnull 10
4: getstatic #31; //Field scala/None$.MODULE$:Lscala/None$;
7: goto 24
10: new #33; //class scala/Some
13: dup
14: aload_1
15: invokevirtual #37; //Method State2.foo$2:()I
18: invokestatic #43; //Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer;
21: invokespecial #46; //Method scala/Some."<init>":(Ljava/lang/Object;)V
24: areturn
LocalVariableTable:
Start Length Slot Name Signature
0 25 0 this LState2$;
0 25 1 x$0 LState2;
scala> :quit
The following code fails with
value foo$1 is not a member of foo.State
:Note that the companion object is necessary to fail. A presentation compiler test is available here
The text was updated successfully, but these errors were encountered: