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

Spurious errors in case classes with private vals #8943

Closed
scabug opened this issue Oct 28, 2014 · 2 comments
Closed

Spurious errors in case classes with private vals #8943

scabug opened this issue Oct 28, 2014 · 2 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Oct 28, 2014

The following code fails with value foo$1 is not a member of foo.State:

package foo

object State
case class State(private val foo: Int)

Note that the companion object is necessary to fail. A presentation compiler test is available here

@scabug
Copy link
Author

scabug commented Oct 28, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8943?orig=1
Reporter: @dragos
Affected Versions: 2.11.4

@scabug
Copy link
Author

scabug commented Oct 29, 2014

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants