diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala | 10 | ||||
-rw-r--r-- | test/files/neg/t6666.check | 9 | ||||
-rw-r--r-- | test/files/neg/t6666.scala | 10 |
3 files changed, 20 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala index a86d8aa2d6..0575254c26 100644 --- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala +++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala @@ -269,10 +269,10 @@ abstract class ExplicitOuter extends InfoTransform } - /** The stack of constructor symbols in which a call to this() or to the super - * constructor is active. + /** The stack of class symbols in which a call to this() or to the super + * constructor, or early definition is active */ - protected def isUnderConstruction(clazz: Symbol) = selfOrSuperCalls exists (_.owner == clazz) + protected def isUnderConstruction(clazz: Symbol) = selfOrSuperCalls contains clazz protected val selfOrSuperCalls = mutable.Stack[Symbol]() @inline protected def inSelfOrSuperCall[A](sym: Symbol)(a: => A) = { selfOrSuperCalls push sym @@ -292,8 +292,8 @@ abstract class ExplicitOuter extends InfoTransform } case _ => } - if (treeInfo isSelfOrSuperConstrCall tree) // TODO also handle (and test) (treeInfo isEarlyDef tree) - inSelfOrSuperCall(currentOwner)(super.transform(tree)) + if ((treeInfo isSelfOrSuperConstrCall tree) || (treeInfo isEarlyDef tree)) + inSelfOrSuperCall(currentOwner.owner)(super.transform(tree)) else super.transform(tree) } diff --git a/test/files/neg/t6666.check b/test/files/neg/t6666.check index 63145f6ed7..6337d4c7d9 100644 --- a/test/files/neg/t6666.check +++ b/test/files/neg/t6666.check @@ -16,7 +16,7 @@ t6666.scala:54: error: Implementation restriction: access of value x$7 in class 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 F.hof(() => x) ^ -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 +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 object Nested { def xx = x} ^ 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 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 F.hof(() => x) ^ -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 +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 object Nested { def xx = x} ^ 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 class CInner extends C({foo}) ^ -11 errors found +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 + object Nested { def xx = x} + ^ +12 errors found diff --git a/test/files/neg/t6666.scala b/test/files/neg/t6666.scala index 19073884bd..1919ea3ca9 100644 --- a/test/files/neg/t6666.scala +++ b/test/files/neg/t6666.scala @@ -110,4 +110,12 @@ class C14(a: Any) { class COuter extends C({ def foo = 0 class CInner extends C({foo}) -})
\ No newline at end of file +}) + + +class CEarly(a: Any) extends { + val early = {def x = "".toString + object Nested { def xx = x} + Nested.xx + } +} with AnyRef
\ No newline at end of file |