diff options
author | odersky <odersky@gmail.com> | 2017-01-16 13:40:38 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-16 13:40:38 +1100 |
commit | 2c229a696b87911d1de9c5cb18d73fae2eee848a (patch) | |
tree | f67913f3f6747112cd6e2a65eca72434ac401911 /compiler | |
parent | eed4f2f84d2d593e3e78926cdff0405c6bf5e472 (diff) | |
parent | 871de839c1dad025e2a0afb525b2e868b28048b1 (diff) | |
download | dotty-2c229a696b87911d1de9c5cb18d73fae2eee848a.tar.gz dotty-2c229a696b87911d1de9c5cb18d73fae2eee848a.tar.bz2 dotty-2c229a696b87911d1de9c5cb18d73fae2eee848a.zip |
Merge pull request #1903 from dotty-staging/fix-npe-implicits
Fix NPE in Implicits
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/src/dotty/tools/dotc/typer/Implicits.scala | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index 303953e73..4ebc676ba 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -155,6 +155,14 @@ object Implicits { (ctx.scope eq outerImplicits.ctx.scope)) outerImplicits.level else outerImplicits.level + 1 + /** Is this the outermost implicits? This is the case if it either the implicits + * of NoContext, or the last one before it. + */ + private def isOuterMost = { + val finalImplicits = NoContext.implicits + (this eq finalImplicits) || (outerImplicits eq finalImplicits) + } + /** The implicit references that are eligible for type `tp`. */ def eligible(tp: Type): List[Candidate] = /*>|>*/ track(s"eligible in ctx") /*<|<*/ { if (tp.hash == NotCached) computeEligible(tp) @@ -162,7 +170,7 @@ object Implicits { case Some(eligibles) => def elided(ci: ContextualImplicits): Int = { val n = ci.refs.length - if (ci.outerImplicits == NoContext.implicits) n + if (ci.isOuterMost) n else n + elided(ci.outerImplicits) } if (monitored) record(s"elided eligible refs", elided(this)) @@ -183,7 +191,7 @@ object Implicits { private def computeEligible(tp: Type): List[Candidate] = /*>|>*/ 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 == NoContext.implicits) ownEligible + if (isOuterMost) ownEligible else ownEligible ::: { val shadowed = ownEligible.map(_.ref.name).toSet outerImplicits.eligible(tp).filterNot(cand => shadowed.contains(cand.ref.name)) @@ -192,7 +200,7 @@ object Implicits { override def toString = { val own = s"(implicits: ${refs mkString ","})" - if (outerImplicits == NoContext.implicits) own else own + "\n " + outerImplicits + if (isOuterMost) own else own + "\n " + outerImplicits } /** This context, or a copy, ensuring root import from symbol `root` |