Skip to content

Commit 206ba59

Browse files
authored
Merge pull request #2327 from dotty-staging/fix-#2324
Fix #2324: Check contexts in right order when looking for idents
2 parents 4b76327 + 07f7b1f commit 206ba59

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
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

tests/neg/i1641.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package bar { object bippy extends (Double => String) { def apply(x: Double): St
22
package object println { def bippy(x: Int, y: Int, z: Int) = "(Int, Int, Int)" }
33
object Test {
44
def main(args: Array[String]): Unit = {
5-
println(bar.bippy(5.5))
5+
println(bar.bippy(5.5)) // error
66
println(bar.bippy(1, 2, 3)) // error
77
}
88
}

tests/pos/i2324.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
object A {
2+
def foo: Int = 1
3+
}
4+
object B {
5+
def foo: Int = 2
6+
}
7+
class C {
8+
import A._
9+
import B._
10+
11+
def bar: Int = 4
12+
13+
def foo: Int = 3
14+
15+
println(foo)
16+
}

0 commit comments

Comments
 (0)