Skip to content

Commit 400e371

Browse files
committed
Fix #7876: Hold off with uniqueness checking for imports
Hold off checking uniqueness of imports with checkNewOrShadowed until we have verified that there is no outer package level definition that trumps the conflicting imports.
1 parent 2e3fbfd commit 400e371

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ class Typer extends Namer
173173
previous
174174
}
175175

176+
/** Recurse in outer context. If final result is same as `previous`, check that it
177+
* is new or shadowed. This order of checking is necessary since an
178+
* outer package-level definition might trump two conflicting inner
179+
* imports, so no error should be issued in that case. See i7876.scala.
180+
*/
181+
def recurAndCheckNewOrShadowed(previous: Type, prevPrec: BindingPrec, prevCtx: Context)(given Context): Type =
182+
val found = findRefRecur(previous, prevPrec, prevCtx)
183+
if found eq previous then checkNewOrShadowed(found, prevPrec)
184+
else found
185+
176186
def selection(imp: ImportInfo, name: Name, checkBounds: Boolean) =
177187
if imp.sym.isCompleting then
178188
ctx.warning(i"cyclic ${imp.sym}, ignored", posd.sourcePos)
@@ -322,11 +332,11 @@ class Typer extends Namer
322332
else if (isPossibleImport(NamedImport) && (curImport ne outer.importInfo)) {
323333
val namedImp = namedImportRef(curImport)
324334
if (namedImp.exists)
325-
findRefRecur(checkNewOrShadowed(namedImp, NamedImport), NamedImport, ctx)(outer)
335+
recurAndCheckNewOrShadowed(namedImp, NamedImport, ctx)(given outer)
326336
else if (isPossibleImport(WildImport) && !curImport.sym.isCompleting) {
327337
val wildImp = wildImportRef(curImport)
328338
if (wildImp.exists)
329-
findRefRecur(checkNewOrShadowed(wildImp, WildImport), WildImport, ctx)(outer)
339+
recurAndCheckNewOrShadowed(wildImp, WildImport, ctx)(given outer)
330340
else {
331341
updateUnimported()
332342
loop(ctx)(outer)

tests/pos/i7876.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object foo
2+
object bar
3+
4+
import foo._, bar._
5+
6+
object eq

0 commit comments

Comments
 (0)