@@ -45,11 +45,20 @@ object Implicits {
45
45
*/
46
46
val DelayedImplicit = new Property .Key [TermRef ]
47
47
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
+
48
55
/** 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
+ }
50
59
51
60
/** 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 .
53
62
*/
54
63
abstract class ImplicitRefs (initctx : Context ) {
55
64
implicit val ctx : Context =
@@ -59,7 +68,7 @@ object Implicits {
59
68
def level : Int = 0
60
69
61
70
/** The implicit references */
62
- def refs : List [TermRef ]
71
+ def refs : List [ImplicitDef ]
63
72
64
73
/** Return those references in `refs` that are compatible with type `pt`. */
65
74
protected def filterMatching (pt : Type )(implicit ctx : Context ): List [Candidate ] = track(" filterMatching" ) {
@@ -138,7 +147,7 @@ object Implicits {
138
147
else {
139
148
val nestedCtx = ctx.fresh.addMode(Mode .TypevarsMissContext )
140
149
refs
141
- .filter(ref => nestedCtx.typerState.test(refMatches(ref)(nestedCtx)))
150
+ .filter(ref => nestedCtx.typerState.test(refMatches(ref.implicitRef )(nestedCtx)))
142
151
.map(Candidate (_, level))
143
152
}
144
153
}
@@ -150,7 +159,7 @@ object Implicits {
150
159
*/
151
160
class OfTypeImplicits (tp : Type , val companionRefs : TermRefSet )(initctx : Context ) extends ImplicitRefs (initctx) {
152
161
assert(initctx.typer != null )
153
- lazy val refs : List [TermRef ] = {
162
+ lazy val refs : List [ImplicitDef ] = {
154
163
val buf = new mutable.ListBuffer [TermRef ]
155
164
for (companion <- companionRefs) buf ++= companion.implicitMembers
156
165
buf.toList
@@ -176,7 +185,7 @@ object Implicits {
176
185
* name, b, whereas the name of the symbol is the original name, a.
177
186
* @param outerCtx the next outer context that makes visible further implicits
178
187
*/
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) {
180
189
private val eligibleCache = new mutable.AnyRefMap [Type , List [Candidate ]]
181
190
182
191
/** The level increases if current context has a different owner or scope than
@@ -188,7 +197,7 @@ object Implicits {
188
197
else if (ctx.scala2Mode ||
189
198
(ctx.owner eq outerImplicits.ctx.owner) &&
190
199
(ctx.scope eq outerImplicits.ctx.scope) &&
191
- ! refs.head.name .is(LazyImplicitName )) outerImplicits.level
200
+ ! refs.head.implicitName .is(LazyImplicitName )) outerImplicits.level
192
201
else outerImplicits.level + 1
193
202
194
203
/** Is this the outermost implicits? This is the case if it either the implicits
@@ -231,8 +240,8 @@ object Implicits {
231
240
val ownEligible = filterMatching(tp)
232
241
if (isOuterMost) ownEligible
233
242
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 ))
236
245
}
237
246
}
238
247
@@ -818,7 +827,7 @@ trait Implicits { self: Typer =>
818
827
pt)
819
828
val generated1 = adapt(generated, pt)
820
829
lazy val shadowing =
821
- typed(untpd.Ident (ref.name ) withPos pos.toSynthetic, funProto)(
830
+ typed(untpd.Ident (cand.implicitDef.implicitName ) withPos pos.toSynthetic, funProto)(
822
831
nestedContext().addMode(Mode .ImplicitShadowing ).setExploreTyperState())
823
832
def refSameAs (shadowing : Tree ): Boolean =
824
833
ref.symbol == closureBody(shadowing).symbol || {
0 commit comments