@@ -131,8 +131,7 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete
131
131
else NoSymbol
132
132
133
133
private def createExtensionMethod (imeth : Symbol , staticClass : Symbol )(implicit ctx : Context ): TermSymbol = {
134
- val extensionName = extensionNames(imeth).head.toTermName
135
- val extensionMeth = ctx.newSymbol(staticClass, extensionName,
134
+ val extensionMeth = ctx.newSymbol(staticClass, extensionName(imeth),
136
135
(imeth.flags | Final ) &~ (Override | Protected | AbsOverride ),
137
136
fullyParameterizedType(imeth.info, imeth.owner.asClass),
138
137
privateWithin = imeth.privateWithin, coord = imeth.coord)
@@ -180,48 +179,17 @@ class ExtensionMethods extends MiniPhase with DenotTransformer with FullParamete
180
179
object ExtensionMethods {
181
180
val name : String = " extmethods"
182
181
183
- /** Generate stream of possible names for the extension version of given instance method `imeth`.
184
- * If the method is not overloaded, this stream consists of just "imeth$extension".
185
- * If the method is overloaded, the stream has as first element "imeth$extenionX", where X is the
186
- * index of imeth in the sequence of overloaded alternatives with the same name. This choice will
187
- * always be picked as the name of the generated extension method.
188
- * After this first choice, all other possible indices in the range of 0 until the number
189
- * of overloaded alternatives are returned. The secondary choices are used to find a matching method
190
- * in `extensionMethod` if the first name has the wrong type. We thereby gain a level of insensitivity
191
- * of how overloaded types are ordered between phases and picklings.
192
- */
193
- private def extensionNames (imeth : Symbol )(implicit ctx : Context ): Stream [Name ] = {
194
- val decl = imeth.owner.info.decl(imeth.name)
195
-
196
- /** No longer needed for Dotty, as we are more disciplined with scopes now.
197
- // Bridge generation is done at phase `erasure`, but new scopes are only generated
198
- // for the phase after that. So bridges are visible in earlier phases.
199
- //
200
- // `info.member(imeth.name)` filters these out, but we need to use `decl`
201
- // to restrict ourselves to members defined in the current class, so we
202
- // must do the filtering here.
203
- val declTypeNoBridge = decl.filter(sym => !sym.isBridge).tpe
204
- */
205
- decl match {
206
- case decl : MultiDenotation =>
207
- val alts = decl.alternatives
208
- val index = alts indexOf imeth.denot
209
- assert(index >= 0 , alts + " does not contain " + imeth)
210
- def altName (index : Int ) = UniqueExtMethName (imeth.name.asTermName, index)
211
- altName(index) #:: ((0 until alts.length).toStream filter (index != _) map altName)
212
- case decl =>
213
- assert(decl.exists, imeth.name + " not found in " + imeth.owner + " 's decls: " + imeth.owner.info.decls)
214
- Stream (ExtMethName (imeth.name.asTermName))
215
- }
216
- }
182
+ /** Name of the extension method that corresponds to given instance method `meth`. */
183
+ def extensionName (imeth : Symbol )(implicit ctx : Context ): TermName =
184
+ ExtMethName (imeth.name.asTermName)
217
185
218
186
/** Return the extension method that corresponds to given instance method `meth`. */
219
187
def extensionMethod (imeth : Symbol )(implicit ctx : Context ): TermSymbol =
220
188
ctx.atPhase(ctx.extensionMethodsPhase.next) {
221
189
// FIXME use toStatic instead?
222
190
val companion = imeth.owner.companionModule
223
191
val companionInfo = companion.info
224
- val candidates = extensionNames(imeth) map ( companionInfo.decl(_).symbol) filter (_.exists)
192
+ val candidates = companionInfo.decl(extensionName(imeth)).alternatives
225
193
val matching = candidates filter (c => FullParameterization .memberSignature(c.info) == imeth.signature)
226
194
assert(matching.nonEmpty,
227
195
i """ no extension method found for:
@@ -234,9 +202,7 @@ object ExtensionMethods {
234
202
|
235
203
| Candidates (signatures normalized):
236
204
|
237
- | ${candidates.map(c => c.name + " :" + c.info.signature + " :" + FullParameterization .memberSignature(c.info)).mkString(" \n " )}
238
- |
239
- | Eligible Names: ${extensionNames(imeth).mkString(" ," )}""" )
240
- matching.head.asTerm
205
+ | ${candidates.map(c => c.name + " :" + c.info.signature + " :" + FullParameterization .memberSignature(c.info)).mkString(" \n " )}""" )
206
+ matching.head.symbol.asTerm
241
207
}
242
208
}
0 commit comments