@@ -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)
0 commit comments