@@ -295,21 +295,27 @@ object Implicits:
295
295
* name, b, whereas the name of the symbol is the original name, a.
296
296
* @param outerCtx the next outer context that makes visible further implicits
297
297
*/
298
- class ContextualImplicits (val refs : List [ImplicitRef ], val outerImplicits : ContextualImplicits )(initctx : Context ) extends ImplicitRefs (initctx) {
298
+ class ContextualImplicits (
299
+ val refs : List [ImplicitRef ],
300
+ val outerImplicits : ContextualImplicits ,
301
+ isImport : Boolean )(initctx : Context ) extends ImplicitRefs (initctx) {
299
302
private val eligibleCache = EqHashMap [Type , List [Candidate ]]()
300
303
301
304
/** The level increases if current context has a different owner or scope than
302
305
* the context of the next-outer ImplicitRefs. This is however disabled under
303
306
* Scala2 mode, since we do not want to change the implicit disambiguation then.
304
307
*/
305
308
override val level : Int =
309
+ def isSameOwner = irefCtx.owner eq outerImplicits.irefCtx.owner
310
+ def isSameScope = irefCtx.scope eq outerImplicits.irefCtx.scope
311
+ def isLazyImplicit = refs.head.implicitName.is(LazyImplicitName )
312
+
306
313
if outerImplicits == null then 1
307
314
else if migrateTo3(using irefCtx)
308
- || (irefCtx.owner eq outerImplicits.irefCtx.owner)
309
- && (irefCtx.scope eq outerImplicits.irefCtx.scope)
310
- && ! refs.head.implicitName.is(LazyImplicitName )
315
+ || isSameOwner && (isImport || isSameScope && ! isLazyImplicit)
311
316
then outerImplicits.level
312
317
else outerImplicits.level + 1
318
+ end level
313
319
314
320
/** Is this the outermost implicits? This is the case if it either the implicits
315
321
* of NoContext, or the last one before it.
@@ -370,7 +376,7 @@ object Implicits:
370
376
val outerExcluded = outerImplicits exclude root
371
377
if (irefCtx.importInfo.site.termSymbol == root) outerExcluded
372
378
else if (outerExcluded eq outerImplicits) this
373
- else new ContextualImplicits (refs, outerExcluded)(irefCtx)
379
+ else new ContextualImplicits (refs, outerExcluded, isImport )(irefCtx)
374
380
}
375
381
}
376
382
0 commit comments