Skip to content

Fix NPE in Implicits #1903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,22 @@ 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)
else eligibleCache get tp match {
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))
Expand All @@ -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))
Expand All @@ -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`
Expand Down