Skip to content

Commit 82f8a81

Browse files
committed
Make LazyVals respect scope hygiene.
The previius commit on "Refine & for Denotations" caused NotDefinedHere errors in the backend when compiling dotc/typer. These were tracked down to three occurrences in LazyVals where `enter` instead of `enteredAfter` was used. `enter` will enter a symbol in an unknown set of previous phases. Transformations that traverse scope (like erasedMembers in TypeErasure will then see the denotations of these symbols outside the scope in which they are defined.
1 parent 4182fb7 commit 82f8a81

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/dotty/tools/dotc/transform/LazyVals.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer {
175175
val containerSymbol = ctx.newSymbol(claz, containerName,
176176
x.symbol.flags &~ containerFlagsMask | containerFlags | Flags.Private,
177177
tpe, coord = x.symbol.coord
178-
).entered
178+
).enteredAfter(this)
179179

180180
val containerTree = ValDef(containerSymbol, defaultValue(tpe))
181181
if (x.tpe.isNotNull && tpe <:< defn.ObjectType) { // can use 'null' value instead of flag
@@ -184,7 +184,7 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer {
184184
}
185185
else {
186186
val flagName = ctx.freshName(x.name ++ StdNames.nme.BITMAP_PREFIX).toTermName
187-
val flagSymbol = ctx.newSymbol(x.symbol.owner, flagName, containerFlags | Flags.Private, defn.BooleanType).entered
187+
val flagSymbol = ctx.newSymbol(x.symbol.owner, flagName, containerFlags | Flags.Private, defn.BooleanType).enteredAfter(this)
188188
val flag = ValDef(flagSymbol, Literal(Constants.Constant(false)))
189189
val slowPath = DefDef(x.symbol.asTerm, mkNonThreadSafeDef(ref(containerSymbol), ref(flagSymbol), x.rhs))
190190
Thicket(List(containerTree, flag, slowPath))
@@ -331,7 +331,7 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer {
331331
}
332332

333333
val containerName = ctx.freshName(x.name ++ StdNames.nme.LAZY_LOCAL).toTermName
334-
val containerSymbol = ctx.newSymbol(claz, containerName, (x.mods &~ containerFlagsMask | containerFlags).flags, tpe, coord = x.symbol.coord).entered
334+
val containerSymbol = ctx.newSymbol(claz, containerName, (x.mods &~ containerFlagsMask | containerFlags).flags, tpe, coord = x.symbol.coord).enteredAfter(this)
335335
val containerTree = ValDef(containerSymbol, defaultValue(tpe))
336336

337337
val offset = ref(companion).ensureApplied.select(offsetSymbol)

0 commit comments

Comments
 (0)