summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2010-05-26 11:52:11 +0000
committerAdriaan Moors <adriaan.moors@epfl.ch>2010-05-26 11:52:11 +0000
commitbf7eee08892aa38130dda75cfb6099fdc8b5bcd4 (patch)
tree03a384d198db3443c056abe2bcecec852843812d /src
parent0301bcfa431cceb6fbf55c7a6c31c611e17e6066 (diff)
downloadscala-bf7eee08892aa38130dda75cfb6099fdc8b5bcd4.tar.gz
scala-bf7eee08892aa38130dda75cfb6099fdc8b5bcd4.tar.bz2
scala-bf7eee08892aa38130dda75cfb6099fdc8b5bcd4.zip
also consider non-implicit locals when checking...
also consider non-implicit locals when checking shadowing of implicits: closes #3453 nonImplicitSynonymInScope implements the predicate that is used in tryImplicit's checks for shadowing of locally defined implicits benchmarking shows the predicate does not significantly affect quick.comp+quick.lib (goes from 11min to 11min2s on my machine -- no optimisations) review by odersky
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Implicits.scala20
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)