Skip to content

Commit d53245a

Browse files
authored
Merge pull request #7889 from dotty-staging/fix-#7876
Fix #7876: Hold off with uniqueness checking for imports
2 parents a8ea206 + 400e371 commit d53245a

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
@@ -174,6 +174,16 @@ class Typer extends Namer
174174
previous
175175
}
176176

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