@@ -471,7 +471,22 @@ trait ImplicitRunInfo { self: Run =>
471
471
472
472
private val EmptyTermRefSet = new TermRefSet ()(NoContext )
473
473
474
- /** The implicit scope of a type `tp`
474
+ /** The implicit scope of a type `tp`, defined as follows:
475
+ *
476
+ * The implicit scope of a type `tp` is the smallest set S of object references (i.e. TermRefs
477
+ * with Module symbol) such that
478
+ *
479
+ * - If `tp` is a class reference, S contains a reference to the companion object of the class,
480
+ * if it exists, as well as the implicit scopes of all of `tp`'s parent class references.
481
+ * - If `tp` is an opaque type alias `p.A` of type `tp'`, S contains a reference to an object `A` defined in the
482
+ * same scope as the opaque type, if it exists, as well as the implicit scope of `tp'`.
483
+ * - If `tp` is a reference `p.T` to a class or opaque type alias, S also contains all object references
484
+ * on the prefix path `p`. Under Scala-2 mode, package objects of package references on `p` also
485
+ * count towards the implicit scope.
486
+ * - If `tp` is an alias of `tp'`, S contains the implicit scope of `tp'`.
487
+ * - If `tp` is some other type, its implicit scope is the union of the implicit scopes of
488
+ * its parts (parts defined as in the spec).
489
+ *
475
490
* @param liftingCtx A context to be used when computing the class symbols of
476
491
* a type. Types may contain type variables with their instances
477
492
* recorded in the current context. To find out the instance of
@@ -545,16 +560,14 @@ trait ImplicitRunInfo { self: Run =>
545
560
val comps = new TermRefSet
546
561
def addCompanion (pre : Type , companion : Symbol ) =
547
562
if (companion.exists && ! companion.isAbsent) comps += TermRef (pre, companion)
548
- def addCompanionNamed (pre : Type , name : TermName ) =
549
- addCompanion(pre, pre.member(name).suchThat(_.is(Module )).symbol)
550
563
551
564
def addPath (pre : Type ): Unit = pre.dealias match {
552
565
case pre : ThisType if pre.cls.is(Module ) && pre.cls.isStaticOwner =>
553
566
addPath(pre.cls.sourceModule.termRef)
554
567
case pre : TermRef =>
555
568
if (pre.symbol.is(Package )) {
556
569
if (ctx.scala2Mode) {
557
- addCompanionNamed (pre, nme.PACKAGE )
570
+ addCompanion (pre, pre.member( nme.PACKAGE ).symbol )
558
571
addPath(pre.prefix)
559
572
}
560
573
}
@@ -564,21 +577,21 @@ trait ImplicitRunInfo { self: Run =>
564
577
}
565
578
case _ =>
566
579
}
567
- tp match {
568
- case tp : TermRef =>
569
- addPath(tp.prefix)
580
+ tp.dealias match {
570
581
case tp : TypeRef =>
571
582
val sym = tp.symbol
572
583
if (isAnchor(sym)) {
573
584
val pre = tp.prefix
574
585
addPath(pre)
575
- if (sym.is(Module )) addCompanion(pre, sym.sourceModule)
576
- else if (sym.isClass) addCompanion(pre, sym.companionModule)
577
- else addCompanionNamed(pre, sym.name.stripModuleClassSuffix.toTermName)
586
+ if (sym.isClass) addCompanion(pre, sym.companionModule)
587
+ else addCompanion(pre,
588
+ pre.member(sym.name.toTermName)
589
+ .suchThat(companion => companion.is(Module ) && companion.owner == sym.owner)
590
+ .symbol)
578
591
}
579
592
val superAnchors = if (sym.isClass) tp.parents else anchors(tp.superType)
580
593
for (anchor <- superAnchors) comps ++= iscopeRefs(anchor)
581
- case _ =>
594
+ case tp =>
582
595
for (part <- tp.namedPartsWith(_.isType)) comps ++= iscopeRefs(part)
583
596
}
584
597
comps
0 commit comments