@@ -224,6 +224,12 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
224
224
def DefDef (sym : TermSymbol , rhs : Tree = EmptyTree )(using Context ): DefDef =
225
225
ta.assignType(DefDef (sym, Function .const(rhs) _), sym)
226
226
227
+ /** A DefDef with given method symbol `sym`.
228
+ * @rhsFn A function from parameter references
229
+ * to the method's right-hand side.
230
+ * Parameter symbols are taken from the `rawParamss` field of `sym`, or
231
+ * are freshly generated if `rawParamss` is empty.
232
+ */
227
233
def DefDef (sym : TermSymbol , rhsFn : List [List [Tree ]] => Tree )(using Context ): DefDef =
228
234
229
235
// Map method type `tp` with remaining parameters stored in rawParamss to
@@ -277,69 +283,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
277
283
DefDef (sym, paramss, rtp, rhsFn(paramss.nestedMap(ref)))
278
284
end DefDef
279
285
280
- /** A DefDef with given method symbol `sym`.
281
- * @rhsFn A function from type parameter types and term parameter references
282
- * to the method's right-hand side.
283
- * Parameter symbols are taken from the `rawParamss` field of `sym`, or
284
- * are freshly generated if `rawParamss` is empty.
285
- */
286
- def polyDefDef (sym : TermSymbol , rhsFn : List [Tree ] => List [List [Tree ]] => Tree )(using Context ): DefDef = {
287
-
288
- val (tparams, existingParamss, mtp) = sym.info match {
289
- case tp : PolyType =>
290
- val (tparams, existingParamss) = sym.rawParamss match
291
- case tparams :: vparamss =>
292
- assert(tparams.hasSameLengthAs(tp.paramNames) && tparams.head.isType)
293
- (tparams.asInstanceOf [List [TypeSymbol ]], vparamss)
294
- case _ =>
295
- (newTypeParams(sym, tp.paramNames, EmptyFlags , tp.instantiateParamInfos(_)), Nil )
296
- (tparams, existingParamss, tp.instantiate(tparams map (_.typeRef)))
297
- case tp => (Nil , sym.rawParamss, tp)
298
- }
299
-
300
- def valueParamss (tp : Type , existingParamss : List [List [Symbol ]]): (List [List [TermSymbol ]], Type ) = tp match {
301
- case tp : MethodType =>
302
- val isParamDependent = tp.isParamDependent
303
- val previousParamRefs = if (isParamDependent) mutable.ListBuffer [TermRef ]() else null
304
-
305
- def valueParam (name : TermName , origInfo : Type ): TermSymbol = {
306
- val maybeImplicit =
307
- if (tp.isContextualMethod) Given
308
- else if (tp.isImplicitMethod) Implicit
309
- else EmptyFlags
310
- val maybeErased = if (tp.isErasedMethod) Erased else EmptyFlags
311
-
312
- def makeSym (info : Type ) = newSymbol(sym, name, TermParam | maybeImplicit | maybeErased, info, coord = sym.coord)
313
-
314
- if (isParamDependent) {
315
- val sym = makeSym(origInfo.substParams(tp, previousParamRefs.toList))
316
- previousParamRefs += sym.termRef
317
- sym
318
- }
319
- else
320
- makeSym(origInfo)
321
- }
322
-
323
- val (params, existingParamss1) =
324
- if tp.paramInfos.isEmpty then (Nil , existingParamss)
325
- else existingParamss match
326
- case vparams :: existingParamss1 =>
327
- assert(vparams.hasSameLengthAs(tp.paramNames) && vparams.head.isTerm)
328
- (vparams.asInstanceOf [List [TermSymbol ]], existingParamss1)
329
- case _ =>
330
- (tp.paramNames.lazyZip(tp.paramInfos).map(valueParam), Nil )
331
- val (paramss, rtp) =
332
- valueParamss(tp.instantiate(params map (_.termRef)), existingParamss1)
333
- (params :: paramss, rtp)
334
- case tp => (Nil , tp.widenExpr)
335
- }
336
- val (vparamss, rtp) = valueParamss(mtp, existingParamss)
337
- val targs = tparams.map(tparam => ref(tparam.typeRef))
338
- val argss = vparamss.nestedMap(vparam => Ident (vparam.termRef))
339
- sym.setParamss(tparams :: vparamss)
340
- DefDef (sym, joinSymbols(tparams, vparamss), rtp, rhsFn(targs)(argss))
341
- }
342
-
343
286
def TypeDef (sym : TypeSymbol )(using Context ): TypeDef =
344
287
ta.assignType(untpd.TypeDef (sym.name, TypeTree (sym.info)), sym)
345
288
@@ -404,7 +347,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
404
347
def forwarder (fn : TermSymbol , name : TermName ) = {
405
348
val fwdMeth = fn.copy(cls, name, Synthetic | Method | Final ).entered.asTerm
406
349
if (fwdMeth.allOverriddenSymbols.exists(! _.is(Deferred ))) fwdMeth.setFlag(Override )
407
- polyDefDef (fwdMeth, tprefs => prefss => ref(fn).appliedToTypeTrees(tprefs). appliedToArgss(prefss ))
350
+ DefDef (fwdMeth, ref(fn).appliedToArgss(_ ))
408
351
}
409
352
val forwarders = fns.lazyZip(methNames).map(forwarder)
410
353
val cdef = ClassDef (cls, DefDef (constr), forwarders)
@@ -1285,12 +1228,21 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
1285
1228
Ident (defn.ScalaRuntimeModule .requiredMethod(name).termRef).appliedToTermArgs(args)
1286
1229
1287
1230
/** An extractor that pulls out type arguments */
1288
- object MaybePoly {
1289
- def unapply (tree : Tree ): Option [(Tree , List [Tree ])] = tree match {
1231
+ object MaybePoly :
1232
+ def unapply (tree : Tree ): Option [(Tree , List [Tree ])] = tree match
1290
1233
case TypeApply (tree, targs) => Some (tree, targs)
1291
1234
case _ => Some (tree, Nil )
1292
- }
1293
- }
1235
+
1236
+ object TypeArgs :
1237
+ def unapply (ts : List [Tree ]): Option [List [Tree ]] =
1238
+ if ts.nonEmpty && ts.head.isType then Some (ts) else None
1239
+
1240
+ /** Split argument clauses into a leading type argument clause if it exists and
1241
+ * remaining clauses
1242
+ */
1243
+ def splitArgs (argss : List [List [Tree ]]): (List [Tree ], List [List [Tree ]]) = argss match
1244
+ case TypeArgs (targs) :: argss1 => (targs, argss1)
1245
+ case _ => (Nil , argss)
1294
1246
1295
1247
/** A key to be used in a context property that tracks enclosing inlined calls */
1296
1248
private val InlinedCalls = Property .Key [List [Tree ]]()
0 commit comments