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.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@19247 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
extempore 2009-10-22 21:09:57 +00:00
parent 5d8cf657ec
commit 7770fad82b
4 changed files with 19 additions and 0 deletions

View File

@ -521,6 +521,10 @@ trait Symbols {
/** Does this symbol denote the primary constructor of its enclosing class? */
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 =

View File

@ -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)

View File

@ -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

View File

@ -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)
}