Skip to content

Commit

Permalink
Fix #7876: Hold off with uniqueness checking for imports
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odersky committed Jan 2, 2020
1 parent 2e3fbfd commit 400e371
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 12 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ class Typer extends Namer
previous
}

/** Recurse in outer context. If final result is same as `previous`, check that it
* is new or shadowed. This order of checking is necessary since an
* outer package-level definition might trump two conflicting inner
* imports, so no error should be issued in that case. See i7876.scala.
*/
def recurAndCheckNewOrShadowed(previous: Type, prevPrec: BindingPrec, prevCtx: Context)(given Context): Type =
val found = findRefRecur(previous, prevPrec, prevCtx)
if found eq previous then checkNewOrShadowed(found, prevPrec)
else found

def selection(imp: ImportInfo, name: Name, checkBounds: Boolean) =
if imp.sym.isCompleting then
ctx.warning(i"cyclic ${imp.sym}, ignored", posd.sourcePos)
Expand Down Expand Up @@ -322,11 +332,11 @@ class Typer extends Namer
else if (isPossibleImport(NamedImport) && (curImport ne outer.importInfo)) {
val namedImp = namedImportRef(curImport)
if (namedImp.exists)
findRefRecur(checkNewOrShadowed(namedImp, NamedImport), NamedImport, ctx)(outer)
recurAndCheckNewOrShadowed(namedImp, NamedImport, ctx)(given outer)
else if (isPossibleImport(WildImport) && !curImport.sym.isCompleting) {
val wildImp = wildImportRef(curImport)
if (wildImp.exists)
findRefRecur(checkNewOrShadowed(wildImp, WildImport), WildImport, ctx)(outer)
recurAndCheckNewOrShadowed(wildImp, WildImport, ctx)(given outer)
else {
updateUnimported()
loop(ctx)(outer)
Expand Down
6 changes: 6 additions & 0 deletions tests/pos/i7876.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object foo
object bar

import foo._, bar._

object eq

0 comments on commit 400e371

Please sign in to comment.