Skip to content

Commit ba8d9ea

Browse files
committed
Fix for t1002
Need to compile the self type of a class not in the context of the class members but one context further out. Reason: self type should not be able to see the members.
1 parent ac45e12 commit ba8d9ea

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
786786
val constr1 = typed(constr).asInstanceOf[DefDef]
787787
val parents1 = ensureConstrCall(ensureFirstIsClass(
788788
parents mapconserve typedParent, cdef.pos.toSynthetic))
789-
val self1 = typed(self).asInstanceOf[ValDef]
789+
val self1 = typed(self)(ctx.outer).asInstanceOf[ValDef] // outer context where class memebers are not visible
790790
val localDummy = ctx.newLocalDummy(cls, impl.pos)
791791
val body1 = typedStats(body, localDummy)(inClassContext(self1.symbol))
792792
checkNoDoubleDefs(cls)

tests/pos/t0002.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object main {
2+
def main(args: Array[String]) = {
3+
val b = true;
4+
while (b == true) { }
5+
}
6+
}

0 commit comments

Comments
 (0)