summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2012-05-11 00:11:45 +0200
committerJason Zaugg <jzaugg@gmail.com>2012-05-11 07:31:20 +0200
commitd35e74eb6bc13f1f354029c9439cef35aecd972b (patch)
tree14f4e936bd3bf381f97370aa5233b7c9f871fdf4 /src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
parentdf10f921158ea13ce8fb53c8e15ec290ace69d83 (diff)
downloadscala-d35e74eb6bc13f1f354029c9439cef35aecd972b.tar.gz
scala-d35e74eb6bc13f1f354029c9439cef35aecd972b.tar.bz2
scala-d35e74eb6bc13f1f354029c9439cef35aecd972b.zip
Forbid forward refs from self constructor invocations.
Prevents the wheels falling off during later compiler phases, or, worse, during bytecode verification. Closes SI-4098.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/RefChecks.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index 6bed0b1228..b04d768baa 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -1279,6 +1279,15 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R
}
def transformStat(tree: Tree, index: Int): List[Tree] = tree match {
+ case Apply(Select(This(_), nme.CONSTRUCTOR), args) =>
+ assert(index == 0, index)
+ val t = transform(tree)
+ if (currentLevel.maxindex > 0) {
+ // An implementation restriction to avoid VerifyErrors and lazyvals mishaps; see SI-4717
+ debuglog("refsym = " + currentLevel.refsym)
+ unit.error(currentLevel.refpos, "forward reference not allowed from self constructor invocation")
+ }
+ List(t)
case ModuleDef(_, _, _) => eliminateModuleDefs(tree)
case ValDef(_, _, _, _) =>
val tree1 @ ValDef(_, _, _, rhs) = transform(tree) // important to do before forward reference check