Permalink
Browse files

Fix context for type checking early initializers

Before:

scala> class A { class C extends { val x: A = this } with AnyRef }
<console>:7: error: type mismatch;
 found   : A.this.C
 required: A
       class A { class C extends { val x: A = this } with AnyRef }
                                              ^

Note that the same thing is necessary and already done in Namers (see
def createNamer). The whole logic of when and how to create contexts
should be factored out and reused in Namer and Typer.

(
My Hobby [1]: detecting compiler by just looking at its soruce
[1] http://www.explainxkcd.com/wiki/index.php?title=Category:My_Hobby
)
  • Loading branch information...
1 parent 7e836f8 commit f3cdf146709e0dd98533ee77e8ca2566380cb932 @lrytz lrytz committed Feb 1, 2013
Showing with 14 additions and 1 deletion.
  1. +1 −1 src/compiler/scala/tools/nsc/typechecker/Typers.scala
  2. +13 −0 test/files/pos/presuperContext.scala
@@ -2069,7 +2069,7 @@ trait Typers extends Modes with Adaptations with Tags {
val sym = vdef.symbol
val valDefTyper = {
val maybeConstrCtx =
- if (sym.isParameter && sym.owner.isConstructor) context.makeConstructorContext
+ if ((sym.isParameter || sym.isEarlyInitialized) && sym.owner.isConstructor) context.makeConstructorContext
else context
newTyper(maybeConstrCtx.makeNewScope(vdef, sym))
}
@@ -0,0 +1,13 @@
+class A {
+ class C extends { val x: A = this } with AnyRef
+}
+
+class B(x: Int)
+
+class D {
+ class C(x: Int) extends B({val test: D = this; x}) {
+ def this() {
+ this({val test: D = this; 1})
+ }
+ }
+}

0 comments on commit f3cdf14

Please sign in to comment.