@@ -19,6 +19,7 @@ import config.Printers.transforms
1919import  reporting .trace 
2020import  java .lang .StringBuilder 
2121
22+ import  scala .annotation .tailrec 
2223import  scala .collection .mutable .ListBuffer 
2324
2425/**  Helper object to generate generic java signatures, as defined in
@@ -294,36 +295,13 @@ object GenericSignatures {
294295        case  ExprType (restpe) => 
295296          jsig(defn.FunctionType (0 ).appliedTo(restpe))
296297
297-         case  PolyType (tparams,  mtpe :  MethodType )  => 
298-           assert (tparams.nonEmpty )
298+         case  mtd :  MethodOrPoly  => 
299+           val   (tparams, vparams, rte)  =  collectMethodParams(mtd )
299300          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
320301          builder.append('(' )
321-           //  TODO: Update once we support varargs
322-           params.foreach { tp => 
323-             jsig(tp)
324-           }
302+           for  vparam <-  vparams do  jsig(vparam)
325303          builder.append(')' )
326-           methodResultSig(restpe )
304+           methodResultSig(rte )
327305
328306        case  tp : AndType  => 
329307          //  Only intersections appearing as the upper-bound of a type parameter
@@ -475,4 +453,23 @@ object GenericSignatures {
475453        }
476454      else  x
477455  }
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 (tpe : Type ):  Type  =  tpe match 
462+       case  mtd : MethodType  => 
463+         vparams ++=  mtd.paramInfos.filterNot(_.hasAnnotation(defn.ErasedParamAnnot ))
464+         recur(mtd.resType)
465+       case  PolyType (tps, tpe) =>  
466+         tparams ++=  tps
467+         recur(tpe)
468+       case  _ => 
469+         tpe
470+     end  recur 
471+ 
472+     val  rte  =  recur(mtd)
473+     (tparams.toList, vparams.toList, rte)
474+   end  collectMethodParams 
478475}
0 commit comments