summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-10-22 21:09:57 +0000
committerPaul Phillips <paulp@improving.org>2009-10-22 21:09:57 +0000
commit99dae57ebb9204a8c99d063fa0666247134d109d (patch)
tree51c197a601baaafe6d91f94a9bb45849d0c49f0d
parenta074b273122896f4e89d1d4c6dd80ebfb325a5cc (diff)
downloadscala-99dae57ebb9204a8c99d063fa0666247134d109d.tar.gz
scala-99dae57ebb9204a8c99d063fa0666247134d109d.tar.bz2
scala-99dae57ebb9204a8c99d063fa0666247134d109d.zip
Tickets #1909 and #2508 involve code which comp...
Tickets #1909 and #2508 involve code which compiles but then fails at runtime due to invalid bytecode. This commit turns those into compile time errors. Includes negative test case.
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala4
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala5
-rw-r--r--test/files/neg/bug1909.check4
-rw-r--r--test/files/neg/bug1909.scala6
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