aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Implicits.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc/typer/Implicits.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Implicits.scala18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala
index 574db1a3d..2bd1731da 100644
--- a/src/dotty/tools/dotc/typer/Implicits.scala
+++ b/src/dotty/tools/dotc/typer/Implicits.scala
@@ -141,7 +141,7 @@ object Implicits {
case Some(eligibles) =>
def elided(ci: ContextualImplicits): Int = {
val n = ci.refs.length
- if (ci.outerImplicits == null) n
+ if (ci.outerImplicits == NoContext.implicits) n
else n + elided(ci.outerImplicits)
}
if (monitored) record(s"elided eligible refs", elided(this))
@@ -156,7 +156,7 @@ object Implicits {
private def computeEligible(tp: Type): List[TermRef] = /*>|>*/ ctx.traceIndented(i"computeEligible $tp in $refs%, %", implicitsDetailed) /*<|<*/ {
if (monitored) record(s"check eligible refs in ctx", refs.length)
val ownEligible = filterMatching(tp)
- if (outerImplicits == null) ownEligible
+ if (outerImplicits == NoContext.implicits) ownEligible
else ownEligible ::: {
val shadowed = (ownEligible map (_.name)).toSet
outerImplicits.eligible(tp) filterNot (ref => shadowed contains ref.name)
@@ -165,8 +165,20 @@ object Implicits {
override def toString = {
val own = s"(implicits: ${refs mkString ","})"
- if (outerImplicits == null) own else own + "\n " + outerImplicits
+ if (outerImplicits == NoContext.implicits) own else own + "\n " + outerImplicits
}
+
+ /** This context, or a copy, ensuring root import from symbol `root`
+ * is not present in outer implicits.
+ */
+ def exclude(root: Symbol): ContextualImplicits =
+ if (this == NoContext.implicits) this
+ else {
+ val outerExcluded = outerImplicits exclude root
+ if (ctx.importInfo.site.termSymbol == root) outerExcluded
+ else if (outerExcluded eq outerImplicits) this
+ else new ContextualImplicits(refs, outerExcluded)(ctx)
+ }
}
/** The result of an implicit search */