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

VerifyError defining a function in an auxiliary #3832

Closed
scabug opened this issue Sep 9, 2010 · 5 comments
Closed

VerifyError defining a function in an auxiliary #3832

scabug opened this issue Sep 9, 2010 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Sep 9, 2010

The following compiles under 2.8 final but throws a VerifyError when instantiated.

class Test {
  def this(un: Int) = {
    this()
    def test(xs: List[Int]) = xs map (x => x)
    ()
  }                                                                              
}
java.lang.VerifyError: (
  class: Test, method: test$$1 
  signature: (Lscala/collection/immutable/List;)Lscala/collection/immutable/List;)
Incompatible argument to function  

See also #1909.

@scabug
Copy link
Author

scabug commented Sep 9, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3832?orig=1
Reporter: @paulp
Affected Versions: 2.9.0
See #1909, #6666

@scabug
Copy link
Author

scabug commented Sep 14, 2010

@TiarkRompf said:
assigning to you, Hubert, since you fixed #1909

@scabug
Copy link
Author

scabug commented Jun 20, 2012

@hubertp said:
See #5812 for another example.

@scabug
Copy link
Author

scabug commented Aug 28, 2013

@retronym said (edited on Aug 28, 2013 12:54:48 PM UTC):
This is indeed caused by the fix for #1909.

The lifted method test is marked as static.

A shorter reproduction:

scala> class t3832a {
     |   def this(un: Int) = {
     |     this()
     |     def bippy = this
     |     ()
     |   }
     | }
defined class t3832a

scala> new t3832a()
java.lang.VerifyError: (class: t3832a, method: bippy$1 signature: ()Lt3832a;) Accessing value from uninitialized register 0

Reverting #1909:

diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
index 515fa66..0185cca 100644
--- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
+++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
@@ -436,8 +436,6 @@ abstract class LambdaLift extends InfoTransform {
     private def liftDef(tree: Tree): Tree = {
       val sym = tree.symbol
       val oldOwner = sym.owner
-      if (sym.owner.isAuxiliaryConstructor && sym.isMethod)  // # bug 1909
-         sym setFlag STATIC
       sym.owner = sym.owner.enclClass
       if (sym.isClass) sym.owner = sym.owner.toInterface
       if (sym.isMethod) sym setFlag LIFTED
scala> class t3832a {
     |   def this(un: Int) = {
     |     this()
     |     def bippy = this
     |     ()
     |   }
     | }
defined class t3832a

scala> new t3832a()
res0: t3832a = t3832a@2db833ca

private static final t3832a bippy$1();
  Code:
   Stack=1, Locals=1, Args_size=0
   0:	aload_0                   // NO `this` in in a static method!
   1:	areturn
  LineNumberTable:
   line 10: 0

In lambda lift, we should differentiate between arguments to the self-constructor call and subsequent code in the auxillary constructor.

Something similar was done as part of #6666 in explicit outer, see OuterPathTransformer#isUnderConstruction(sym).

@scabug
Copy link
Author

scabug commented Aug 28, 2013

@retronym said:
PR: scala/scala#2884

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

No branches or pull requests

2 participants