diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Implicits.scala | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 20d367337f..3abaf4f337 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -571,6 +571,19 @@ self: Analyzer => /** A set containing names that are shadowed by implicit infos */ lazy val shadowed = new HashSet[Name]("shadowed", 512) + // #3453 + // in addition to the implicit symbols that may shadow the implicit with name `name`, + // this method tests whether there's a non-implicit symbol with name `name` in scope + // inspired by logic in typedIdent + def nonImplicitSynonymInScope(name: Name) = { + val defEntry = context.scope.lookupEntry(name) + (defEntry ne null) && + reallyExists(defEntry.sym) && + !defEntry.sym.isImplicit // the implicit ones are handled by the `shadowed` set above + // also, subsumes the test that defEntry.sym ne info.sym + // (the `info` that's in scope at the call to nonImplicitSynonymInScope in tryImplicit) + } + /** Is `sym' the standard conforms method in Predef? * Note: DON't replace this by sym == Predef_conforms, as Predef_conforms is a `def' * which does a member lookup (it can't be a lazy val because we might reload Predef @@ -592,7 +605,7 @@ self: Analyzer => def tryImplicit(info: ImplicitInfo): SearchResult = { incCounter(triedImplicits) if (info.isCyclicOrErroneous || - (isLocal && shadowed.contains(info.name)) || + (isLocal && (shadowed.contains(info.name) || nonImplicitSynonymInScope(info.name))) || (isView && isConformsMethod(info.sym)) || //@M this condition prevents no-op conversions, which are a problem (besides efficiency), // one example is removeNames in NamesDefaults, which relies on the type checker failing in case of ambiguity between an assignment/named arg @@ -615,6 +628,11 @@ self: Analyzer => applicable } + // #3453 -- alternative fix, seems not to be faster than encoding the set as the boolean predicate nonImplicitSynonymInScope + // in addition to the *implicit* symbols that may shadow the implicit with name `name` (added to shadowed by addAppInfos) + // add names of non-implicit symbols that are in scope (accessible without prefix) + // for(sym <- context.scope; if !sym.isImplicit) shadowed addEntry sym.name + var applicable = Map[ImplicitInfo, SearchResult]() for (is <- iss) applicable = addAppInfos(is, applicable) |