@@ -45,11 +45,20 @@ object Implicits {
4545 */
4646 val DelayedImplicit = new Property .Key [TermRef ]
4747
48+ /** An implicit definition `implicitRef` that is visible under a different name, `alias`.
49+ * Gets generated if an implicit ref is imported via a renaming import.
50+ */
51+ class RenamedImplicitDef (val implicitRef : TermRef , val alias : TermName ) extends ImplicitDef {
52+ def implicitName (implicit ctx : Context ): TermName = alias
53+ }
54+
4855 /** An eligible implicit candidate, consisting of an implicit reference and a nesting level */
49- case class Candidate (ref : TermRef , level : Int )
56+ case class Candidate (implicitDef : ImplicitDef , level : Int ) {
57+ def ref : TermRef = implicitDef.implicitRef
58+ }
5059
5160 /** A common base class of contextual implicits and of-type implicits which
52- * represents a set of implicit references .
61+ * represents a set of references to implicit definitions .
5362 */
5463 abstract class ImplicitRefs (initctx : Context ) {
5564 implicit val ctx : Context =
@@ -59,7 +68,7 @@ object Implicits {
5968 def level : Int = 0
6069
6170 /** The implicit references */
62- def refs : List [TermRef ]
71+ def refs : List [ImplicitDef ]
6372
6473 /** Return those references in `refs` that are compatible with type `pt`. */
6574 protected def filterMatching (pt : Type )(implicit ctx : Context ): List [Candidate ] = track(" filterMatching" ) {
@@ -138,7 +147,7 @@ object Implicits {
138147 else {
139148 val nestedCtx = ctx.fresh.addMode(Mode .TypevarsMissContext )
140149 refs
141- .filter(ref => nestedCtx.typerState.test(refMatches(ref)(nestedCtx)))
150+ .filter(ref => nestedCtx.typerState.test(refMatches(ref.implicitRef )(nestedCtx)))
142151 .map(Candidate (_, level))
143152 }
144153 }
@@ -150,7 +159,7 @@ object Implicits {
150159 */
151160 class OfTypeImplicits (tp : Type , val companionRefs : TermRefSet )(initctx : Context ) extends ImplicitRefs (initctx) {
152161 assert(initctx.typer != null )
153- lazy val refs : List [TermRef ] = {
162+ lazy val refs : List [ImplicitDef ] = {
154163 val buf = new mutable.ListBuffer [TermRef ]
155164 for (companion <- companionRefs) buf ++= companion.implicitMembers
156165 buf.toList
@@ -176,7 +185,7 @@ object Implicits {
176185 * name, b, whereas the name of the symbol is the original name, a.
177186 * @param outerCtx the next outer context that makes visible further implicits
178187 */
179- class ContextualImplicits (val refs : List [TermRef ], val outerImplicits : ContextualImplicits )(initctx : Context ) extends ImplicitRefs (initctx) {
188+ class ContextualImplicits (val refs : List [ImplicitDef ], val outerImplicits : ContextualImplicits )(initctx : Context ) extends ImplicitRefs (initctx) {
180189 private val eligibleCache = new mutable.AnyRefMap [Type , List [Candidate ]]
181190
182191 /** The level increases if current context has a different owner or scope than
@@ -188,7 +197,7 @@ object Implicits {
188197 else if (ctx.scala2Mode ||
189198 (ctx.owner eq outerImplicits.ctx.owner) &&
190199 (ctx.scope eq outerImplicits.ctx.scope) &&
191- ! refs.head.name .is(LazyImplicitName )) outerImplicits.level
200+ ! refs.head.implicitName .is(LazyImplicitName )) outerImplicits.level
192201 else outerImplicits.level + 1
193202
194203 /** Is this the outermost implicits? This is the case if it either the implicits
@@ -231,8 +240,8 @@ object Implicits {
231240 val ownEligible = filterMatching(tp)
232241 if (isOuterMost) ownEligible
233242 else ownEligible ::: {
234- val shadowed = ownEligible.map(_.ref.name ).toSet
235- outerImplicits.eligible(tp).filterNot(cand => shadowed.contains(cand.ref.name ))
243+ val shadowed = ownEligible.map(_.ref.implicitName ).toSet
244+ outerImplicits.eligible(tp).filterNot(cand => shadowed.contains(cand.ref.implicitName ))
236245 }
237246 }
238247
@@ -818,7 +827,7 @@ trait Implicits { self: Typer =>
818827 pt)
819828 val generated1 = adapt(generated, pt)
820829 lazy val shadowing =
821- typed(untpd.Ident (ref.name ) withPos pos.toSynthetic, funProto)(
830+ typed(untpd.Ident (cand.implicitDef.implicitName ) withPos pos.toSynthetic, funProto)(
822831 nestedContext().addMode(Mode .ImplicitShadowing ).setExploreTyperState())
823832 def refSameAs (shadowing : Tree ): Boolean =
824833 ref.symbol == closureBody(shadowing).symbol || {
0 commit comments