summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/transform/LambdaLift.scala11
-rw-r--r--test/files/neg/t1909-object.check4
-rw-r--r--test/files/neg/t1909-object.flags1
-rw-r--r--test/files/neg/t1909-object.scala12
-rw-r--r--test/files/run/t1909c.scala9
-rw-r--r--test/files/run/t3832.scala17
6 files changed, 52 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
index 515fa66cfa..acef2a50d8 100644
--- a/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
+++ b/src/compiler/scala/tools/nsc/transform/LambdaLift.scala
@@ -436,8 +436,15 @@ 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
+ if (sym.isMethod && isUnderConstruction(sym.owner.owner)) { // # bug 1909
+ if (sym.isModule) { // Yes, it can be a module and a method, see comments on `isModuleNotMethod`!
+ // TODO promote to an implementation restriction if we can reason that this *always* leads to VerifyError.
+ // See neg/t1909-object.scala
+ def msg = s"SI-1909 Unable to STATICally lift $sym, which is defined in the self- or super-constructor call of ${sym.owner.owner}. A VerifyError is likely."
+ devWarning(tree.pos, msg)
+ } else sym setFlag STATIC
+ }
+
sym.owner = sym.owner.enclClass
if (sym.isClass) sym.owner = sym.owner.toInterface
if (sym.isMethod) sym setFlag LIFTED
diff --git a/test/files/neg/t1909-object.check b/test/files/neg/t1909-object.check
new file mode 100644
index 0000000000..401c1f7ebf
--- /dev/null
+++ b/test/files/neg/t1909-object.check
@@ -0,0 +1,4 @@
+t1909-object.scala:4: error: !!! SI-1909 Unable to STATICally lift object InnerTrouble$1, which is defined in the self- or super-constructor call of class Kaboom. A VerifyError is likely.
+ object InnerTrouble
+ ^
+one error found
diff --git a/test/files/neg/t1909-object.flags b/test/files/neg/t1909-object.flags
new file mode 100644
index 0000000000..eb8b40661b
--- /dev/null
+++ b/test/files/neg/t1909-object.flags
@@ -0,0 +1 @@
+-Xdev -Xfatal-warnings \ No newline at end of file
diff --git a/test/files/neg/t1909-object.scala b/test/files/neg/t1909-object.scala
new file mode 100644
index 0000000000..d6011ba4a5
--- /dev/null
+++ b/test/files/neg/t1909-object.scala
@@ -0,0 +1,12 @@
+class Kaboom(a: Any) {
+ def this() = {
+ this({
+ object InnerTrouble
+ InnerTrouble
+ })
+ }
+}
+
+object Test extends App {
+ new Kaboom()
+} \ No newline at end of file
diff --git a/test/files/run/t1909c.scala b/test/files/run/t1909c.scala
new file mode 100644
index 0000000000..87c0eb08b5
--- /dev/null
+++ b/test/files/run/t1909c.scala
@@ -0,0 +1,9 @@
+class Base(a: Any)
+
+// java.lang.VerifyError: (class: Sub, method: <init> signature: ()V) Expecting to find object/array on stack
+// at Test$.<init>(t1909c.scala)
+class Sub() extends Base({ def bippy = 5; bippy })
+
+object Test extends App {
+ new Sub()
+}
diff --git a/test/files/run/t3832.scala b/test/files/run/t3832.scala
new file mode 100644
index 0000000000..ac44358bc7
--- /dev/null
+++ b/test/files/run/t3832.scala
@@ -0,0 +1,17 @@
+class t3832 {
+ def this(un: Int) = {
+ this()
+ def bippy = this
+ ()
+ }
+ def this(un: Boolean) = {
+ this()
+ def boppy = () => this
+ ()
+ }
+}
+
+object Test extends App {
+ new t3832(0)
+ new t3832(true)
+}