@@ -155,14 +155,22 @@ object Implicits {
155
155
(ctx.scope eq outerImplicits.ctx.scope)) outerImplicits.level
156
156
else outerImplicits.level + 1
157
157
158
+ /** Is this the outermost implicits? This is the case if it either the implicits
159
+ * of NoContext, or the last one before it.
160
+ */
161
+ private def isOuterMost = {
162
+ val finalImplicits = NoContext .implicits
163
+ (this eq finalImplicits) || (outerImplicits eq finalImplicits)
164
+ }
165
+
158
166
/** The implicit references that are eligible for type `tp`. */
159
167
def eligible (tp : Type ): List [Candidate ] = /* >|>*/ track(s " eligible in ctx " ) /* <|<*/ {
160
168
if (tp.hash == NotCached ) computeEligible(tp)
161
169
else eligibleCache get tp match {
162
170
case Some (eligibles) =>
163
171
def elided (ci : ContextualImplicits ): Int = {
164
172
val n = ci.refs.length
165
- if (ci.outerImplicits == NoContext .implicits ) n
173
+ if (ci.isOuterMost ) n
166
174
else n + elided(ci.outerImplicits)
167
175
}
168
176
if (monitored) record(s " elided eligible refs " , elided(this ))
@@ -183,7 +191,7 @@ object Implicits {
183
191
private def computeEligible (tp : Type ): List [Candidate ] = /* >|>*/ ctx.traceIndented(i " computeEligible $tp in $refs%, % " , implicitsDetailed) /* <|<*/ {
184
192
if (monitored) record(s " check eligible refs in ctx " , refs.length)
185
193
val ownEligible = filterMatching(tp)
186
- if (outerImplicits == NoContext .implicits ) ownEligible
194
+ if (isOuterMost ) ownEligible
187
195
else ownEligible ::: {
188
196
val shadowed = ownEligible.map(_.ref.name).toSet
189
197
outerImplicits.eligible(tp).filterNot(cand => shadowed.contains(cand.ref.name))
@@ -192,7 +200,7 @@ object Implicits {
192
200
193
201
override def toString = {
194
202
val own = s " (implicits: ${refs mkString " ," }) "
195
- if (outerImplicits == NoContext .implicits ) own else own + " \n " + outerImplicits
203
+ if (isOuterMost ) own else own + " \n " + outerImplicits
196
204
}
197
205
198
206
/** This context, or a copy, ensuring root import from symbol `root`
0 commit comments