Skip to content
This repository
Browse code

SI-6666 Catch VerifyErrors in the making in early defs.

As we did for self/super calls, add a backstop into
explicitouter and lambdalift to check when we try to
get an outer pointer to an under-construction instance.
  • Loading branch information...
commit 275b341545a3c4e633bd735cf45ccc1956a4233e 1 parent 66fa1f2
Jason Zaugg retronym authored
10 src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -269,10 +269,10 @@ abstract class ExplicitOuter extends InfoTransform
269 269 }
270 270
271 271
272   - /** The stack of constructor symbols in which a call to this() or to the super
273   - * constructor is active.
  272 + /** The stack of class symbols in which a call to this() or to the super
  273 + * constructor, or early definition is active
274 274 */
275   - protected def isUnderConstruction(clazz: Symbol) = selfOrSuperCalls exists (_.owner == clazz)
  275 + protected def isUnderConstruction(clazz: Symbol) = selfOrSuperCalls contains clazz
276 276 protected val selfOrSuperCalls = mutable.Stack[Symbol]()
277 277 @inline protected def inSelfOrSuperCall[A](sym: Symbol)(a: => A) = {
278 278 selfOrSuperCalls push sym
@@ -292,8 +292,8 @@ abstract class ExplicitOuter extends InfoTransform
292 292 }
293 293 case _ =>
294 294 }
295   - if (treeInfo isSelfOrSuperConstrCall tree) // TODO also handle (and test) (treeInfo isEarlyDef tree)
296   - inSelfOrSuperCall(currentOwner)(super.transform(tree))
  295 + if ((treeInfo isSelfOrSuperConstrCall tree) || (treeInfo isEarlyDef tree))
  296 + inSelfOrSuperCall(currentOwner.owner)(super.transform(tree))
297 297 else
298 298 super.transform(tree)
299 299 }
9 test/files/neg/t6666.check
@@ -16,7 +16,7 @@ t6666.scala:54: error: Implementation restriction: access of value x$7 in class
16 16 t6666.scala:58: error: Implementation restriction: access of method x$8 in class C3 from anonymous class 9, would require illegal premature access to the unconstructed `this` of class C3
17 17 F.hof(() => x)
18 18 ^
19   -t6666.scala:62: error: Implementation restriction: access of method x$9 in class C4 from object Nested$3, would require illegal premature access to the unconstructed `this` of class C4
  19 +t6666.scala:62: error: Implementation restriction: access of method x$9 in class C4 from object Nested$4, would require illegal premature access to the unconstructed `this` of class C4
20 20 object Nested { def xx = x}
21 21 ^
22 22 t6666.scala:76: error: Implementation restriction: access of method x$11 in class C11 from anonymous class 12, would require illegal premature access to the unconstructed `this` of class C11
@@ -25,10 +25,13 @@ t6666.scala:76: error: Implementation restriction: access of method x$11 in clas
25 25 t6666.scala:95: error: Implementation restriction: access of method x$12 in class C13 from anonymous class 13, would require illegal premature access to the unconstructed `this` of class C13
26 26 F.hof(() => x)
27 27 ^
28   -t6666.scala:104: error: Implementation restriction: access of method x$13 in class C14 from object Nested$4, would require illegal premature access to the unconstructed `this` of class C14
  28 +t6666.scala:104: error: Implementation restriction: access of method x$13 in class C14 from object Nested$5, would require illegal premature access to the unconstructed `this` of class C14
29 29 object Nested { def xx = x}
30 30 ^
31 31 t6666.scala:112: error: Implementation restriction: access of method foo$1 in class COuter from class CInner$1, would require illegal premature access to the unconstructed `this` of class COuter
32 32 class CInner extends C({foo})
33 33 ^
34   -11 errors found
  34 +t6666.scala:118: error: Implementation restriction: access of method x$14 in class CEarly from object Nested$6, would require illegal premature access to the unconstructed `this` of class CEarly
  35 + object Nested { def xx = x}
  36 + ^
  37 +12 errors found
10 test/files/neg/t6666.scala
@@ -110,4 +110,12 @@ class C14(a: Any) {
110 110 class COuter extends C({
111 111 def foo = 0
112 112 class CInner extends C({foo})
113   -})
  113 +})
  114 +
  115 +
  116 +class CEarly(a: Any) extends {
  117 + val early = {def x = "".toString
  118 + object Nested { def xx = x}
  119 + Nested.xx
  120 + }
  121 +} with AnyRef

0 comments on commit 275b341

Please sign in to comment.
Something went wrong with that request. Please try again.