Skip to content

Commit

Permalink
Forgive import ambiguity at level 4 binding
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed May 3, 2018
1 parent 5e1aa8d commit 8784687
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/compiler/scala/tools/nsc/typechecker/Contexts.scala
Expand Up @@ -1009,6 +1009,12 @@ trait Contexts { self: Analyzer =>
)
}

private def reconcileAmbiguousImportAndDef(name: Name, imp1: ImportInfo, impSym: Symbol, defSym: Symbol): Boolean = {
val res = impSym == defSym
if (res) log(s"Suppressing ambiguous import, taking $defSym for $name")
res
}

/** The symbol with name `name` imported via the import in `imp`,
* if any such symbol is accessible from this context.
*/
Expand Down Expand Up @@ -1161,6 +1167,9 @@ trait Contexts { self: Analyzer =>
// Defined symbols take precedence over erroneous imports.
else if (impSym.isError || impSym.name == nme.CONSTRUCTOR)
impSym = NoSymbol
// Try to reconcile them before giving up, at least if the def is not visible
else if (foreignDefined && reconcileAmbiguousImportAndDef(name, imp1, impSym, defSym))
impSym = NoSymbol
// Otherwise they are irreconcilably ambiguous
else
return ambiguousDefnAndImport(defSym.alternatives.head.owner, imp1)
Expand Down

0 comments on commit 8784687

Please sign in to comment.