@@ -471,7 +471,22 @@ trait ImplicitRunInfo { self: Run =>
471471
472472 private val EmptyTermRefSet = new TermRefSet ()(NoContext )
473473
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+ *
475490 * @param liftingCtx A context to be used when computing the class symbols of
476491 * a type. Types may contain type variables with their instances
477492 * recorded in the current context. To find out the instance of
@@ -545,16 +560,14 @@ trait ImplicitRunInfo { self: Run =>
545560 val comps = new TermRefSet
546561 def addCompanion (pre : Type , companion : Symbol ) =
547562 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)
550563
551564 def addPath (pre : Type ): Unit = pre.dealias match {
552565 case pre : ThisType if pre.cls.is(Module ) && pre.cls.isStaticOwner =>
553566 addPath(pre.cls.sourceModule.termRef)
554567 case pre : TermRef =>
555568 if (pre.symbol.is(Package )) {
556569 if (ctx.scala2Mode) {
557- addCompanionNamed (pre, nme.PACKAGE )
570+ addCompanion (pre, pre.member( nme.PACKAGE ).symbol )
558571 addPath(pre.prefix)
559572 }
560573 }
@@ -564,21 +577,21 @@ trait ImplicitRunInfo { self: Run =>
564577 }
565578 case _ =>
566579 }
567- tp match {
568- case tp : TermRef =>
569- addPath(tp.prefix)
580+ tp.dealias match {
570581 case tp : TypeRef =>
571582 val sym = tp.symbol
572583 if (isAnchor(sym)) {
573584 val pre = tp.prefix
574585 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)
578591 }
579592 val superAnchors = if (sym.isClass) tp.parents else anchors(tp.superType)
580593 for (anchor <- superAnchors) comps ++= iscopeRefs(anchor)
581- case _ =>
594+ case tp =>
582595 for (part <- tp.namedPartsWith(_.isType)) comps ++= iscopeRefs(part)
583596 }
584597 comps
0 commit comments