Skip to content

Commit

Permalink
Fix context for type checking early initializers
Browse files Browse the repository at this point in the history
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
lrytz committed Feb 3, 2013
1 parent 7e836f8 commit f3cdf14
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/typechecker/Typers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
13 changes: 13 additions & 0 deletions test/files/pos/presuperContext.scala
Original file line number Diff line number Diff line change
@@ -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.