diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Symbols.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/UnCurry.scala | 5 | ||||
-rw-r--r-- | test/files/neg/bug1909.check | 4 | ||||
-rw-r--r-- | test/files/neg/bug1909.scala | 6 |
4 files changed, 19 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 43abc6501d..a781971670 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -522,6 +522,10 @@ trait Symbols { final def isPrimaryConstructor = isConstructor && owner.primaryConstructor == this + /** Does this symbol denote an auxiliary constructor of its enclosing class? */ + final def isAuxiliaryConstructor = + isConstructor && !isPrimaryConstructor + /** Is this symbol a synthetic apply or unapply method in a companion object of a case class? */ final def isCaseApplyOrUnapply = isMethod && hasFlag(CASE) && hasFlag(SYNTHETIC) diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index 96e40f1fe5..d87fadf3dd 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -485,6 +485,11 @@ abstract class UnCurry extends InfoTransform with TypingTransformers { def liftTree(tree: Tree) = { if (settings.debug.value) log("lifting tree at: " + (tree.pos)) + + // Until/unless #1909 is fixed, much better to not compile than to fail at runtime. + if (currentOwner.isAuxiliaryConstructor) + unit.error(tree.pos, "Implementation restriction: auxiliary constructor calls may not use expressions which require lifting.") + val sym = currentOwner.newMethod(tree.pos, unit.fresh.newName(tree.pos, "liftedTree")) sym.setInfo(MethodType(List(), tree.tpe)) new ChangeOwnerTraverser(currentOwner, sym).traverse(tree) diff --git a/test/files/neg/bug1909.check b/test/files/neg/bug1909.check new file mode 100644 index 0000000000..631c60d5f0 --- /dev/null +++ b/test/files/neg/bug1909.check @@ -0,0 +1,4 @@ +bug1909.scala:5: error: Implementation restriction: auxiliary constructor calls may not use expressions which require lifting. + def this(p: String) = this(try 0) + ^ +one error found diff --git a/test/files/neg/bug1909.scala b/test/files/neg/bug1909.scala new file mode 100644 index 0000000000..4fae4e5414 --- /dev/null +++ b/test/files/neg/bug1909.scala @@ -0,0 +1,6 @@ +// Until #1909 is fixed, if this compiles the bytecode +// will trigger a VerifyError. +class Class { + def this(value: Int) = this() + def this(p: String) = this(try 0) +}
\ No newline at end of file |