@@ -19,6 +19,7 @@ import config.Printers.transforms
19
19
import reporting .trace
20
20
import java .lang .StringBuilder
21
21
22
+ import scala .annotation .tailrec
22
23
import scala .collection .mutable .ListBuffer
23
24
24
25
/** Helper object to generate generic java signatures, as defined in
@@ -294,36 +295,13 @@ object GenericSignatures {
294
295
case ExprType (restpe) =>
295
296
jsig(defn.FunctionType (0 ).appliedTo(restpe))
296
297
297
- case PolyType (tparams, mtpe : MethodType ) =>
298
- assert (tparams.nonEmpty )
298
+ case mtd : MethodOrPoly =>
299
+ val (tparams, vparams, rte) = collectMethodParams(mtd )
299
300
if (toplevel && ! sym0.isConstructor) polyParamSig(tparams)
300
- jsig(mtpe)
301
-
302
- // Nullary polymorphic method
303
- case PolyType (tparams, restpe) =>
304
- assert(tparams.nonEmpty)
305
- if (toplevel) polyParamSig(tparams)
306
- builder.append(" ()" )
307
- methodResultSig(restpe)
308
-
309
- case mtpe : MethodType =>
310
- // erased method parameters do not make it to the bytecode.
311
- def effectiveParamInfoss (t : Type )(using Context ): List [List [Type ]] = t match {
312
- case t : MethodType if t.hasErasedParams =>
313
- t.paramInfos.zip(t.erasedParams).collect{ case (i, false ) => i }
314
- :: effectiveParamInfoss(t.resType)
315
- case t : MethodType => t.paramInfos :: effectiveParamInfoss(t.resType)
316
- case _ => Nil
317
- }
318
- val params = effectiveParamInfoss(mtpe).flatten
319
- val restpe = mtpe.finalResultType
320
301
builder.append('(' )
321
- // TODO: Update once we support varargs
322
- params.foreach { tp =>
323
- jsig(tp)
324
- }
302
+ for vparam <- vparams do jsig(vparam)
325
303
builder.append(')' )
326
- methodResultSig(restpe )
304
+ methodResultSig(rte )
327
305
328
306
case tp : AndType =>
329
307
// Only intersections appearing as the upper-bound of a type parameter
@@ -475,4 +453,28 @@ object GenericSignatures {
475
453
}
476
454
else x
477
455
}
456
+
457
+ private def collectMethodParams (mtd : MethodOrPoly )(using Context ): (List [TypeParamInfo ], List [Type ], Type ) =
458
+ val tparams = ListBuffer .empty[TypeParamInfo ]
459
+ val vparams = ListBuffer .empty[Type ]
460
+
461
+ @ tailrec def recur (mtd : MethodOrPoly ): Type = mtd match
462
+ case mtd : MethodType => mtd.resType match
463
+ case ret : MethodOrPoly =>
464
+ vparams ++= mtd.paramInfos.filterNot(_.hasAnnotation(defn.ErasedParamAnnot ))
465
+ recur(ret)
466
+ case tpe =>
467
+ vparams ++= mtd.paramInfos.filterNot(_.hasAnnotation(defn.ErasedParamAnnot ))
468
+ tpe
469
+ case PolyType (tps, mtpe : MethodType ) =>
470
+ tparams ++= tps
471
+ recur(mtpe)
472
+ case PolyType (tps, tpe) =>
473
+ tparams ++= tps
474
+ tpe
475
+ end recur
476
+
477
+ val rte = recur(mtd)
478
+ (tparams.toList, vparams.toList, rte)
479
+ end collectMethodParams
478
480
}
0 commit comments