Skip to content

Commit 184efe1

Browse files
committed
Fix #2324: Check contexts in right order when looking for idents
The previous logic would look for members of a class in the outermost scope where the class is owner. But it should be the innermost scope.
1 parent fa13f8d commit 184efe1

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
253253
!noImports &&
254254
(prevPrec < prec || prevPrec == prec && (prevCtx.scope eq ctx.scope))
255255

256-
@tailrec def loop(implicit ctx: Context): Type = {
256+
@tailrec def loop(lastCtx: Context)(implicit ctx: Context): Type = {
257257
if (ctx.scope == null) previous
258258
else {
259-
val outer = ctx.outer
260259
var result: Type = NoType
261260

262261
// find definition
263-
if ((ctx.scope ne outer.scope) || (ctx.owner ne outer.owner)) {
262+
if ((lastCtx eq ctx) || (ctx.scope ne lastCtx.scope) || (ctx.owner ne lastCtx.owner)) {
264263
val defDenot = ctx.denotNamed(name)
265264
if (qualifies(defDenot)) {
266265
val curOwner = ctx.owner
@@ -275,13 +274,14 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
275274
if (defDenot.symbol is Package)
276275
result = checkNewOrShadowed(previous orElse found, packageClause)
277276
else if (prevPrec < packageClause)
278-
result = findRef(found, packageClause, ctx)(outer)
277+
result = findRef(found, packageClause, ctx)(ctx.outer)
279278
}
280279
}
281280
}
282281

283282
if (result.exists) result
284283
else { // find import
284+
val outer = ctx.outer
285285
val curImport = ctx.importInfo
286286
def updateUnimported() =
287287
if (curImport.unimported.exists) unimported += curImport.unimported
@@ -297,20 +297,21 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
297297
findRef(checkNewOrShadowed(wildImp, wildImport), wildImport, ctx)(outer)
298298
else {
299299
updateUnimported()
300-
loop(outer)
300+
loop(ctx)(outer)
301301
}
302302
}
303303
else {
304304
updateUnimported()
305-
loop(outer)
305+
loop(ctx)(outer)
306306
}
307307
}
308-
else loop(outer)
308+
else loop(ctx)(outer)
309309
}
310310
}
311311
}
312312

313-
loop
313+
// begin findRef
314+
loop(ctx)(ctx)
314315
}
315316

316317
// begin typedIdent

0 commit comments

Comments
 (0)