@@ -447,24 +447,16 @@ object Erasure {
447
447
private def runtimeCallWithProtoArgs (name : Name , pt : Type , args : Tree * )(implicit ctx : Context ): Tree = {
448
448
val meth = defn.runtimeMethodRef(name)
449
449
val followingParams = meth.symbol.info.firstParamTypes.drop(args.length)
450
- val followingArgs = protoArgs(pt).zipWithConserve(followingParams)(typedExpr).asInstanceOf [List [tpd.Tree ]]
450
+ val followingArgs = protoArgs(pt, meth.widen ).zipWithConserve(followingParams)(typedExpr).asInstanceOf [List [tpd.Tree ]]
451
451
ref(meth).appliedToArgs(args.toList ++ followingArgs)
452
452
}
453
453
454
- private def protoArgs (pt : Type ): List [untpd.Tree ] = pt match {
455
- case pt : FunProto => pt.args ++ protoArgs(pt.resType)
454
+ private def protoArgs (pt : Type , tp : Type ): List [untpd.Tree ] = (pt, tp) match {
455
+ case (pt : FunProto , tp : MethodType ) if tp.isUnusedMethod => protoArgs(pt.resType, tp.resType)
456
+ case (pt : FunProto , tp : MethodType ) => pt.args ++ protoArgs(pt.resType, tp.resType)
456
457
case _ => Nil
457
458
}
458
459
459
- // TODO: merge this whit protoArgs if it is actually needed
460
- private def protoArgs2 (pt : Type , tp : Type ): List [untpd.Tree ] = (pt, tp) match {
461
- case (pt : FunProto , tp : MethodType ) if tp.isUnusedMethod => protoArgs2(pt.resType, tp.resType)
462
- case (pt : FunProto , tp : MethodType ) => pt.args ++ protoArgs2(pt.resType, tp.resType)
463
- case _ =>
464
- assert(! tp.isInstanceOf [MethodOrPoly ], tp)
465
- Nil
466
- }
467
-
468
460
override def typedTypeApply (tree : untpd.TypeApply , pt : Type )(implicit ctx : Context ) = {
469
461
val ntree = interceptTypeApply(tree.asInstanceOf [TypeApply ])(ctx.withPhase(ctx.erasurePhase))
470
462
@@ -495,8 +487,8 @@ object Erasure {
495
487
fun1.tpe.widen match {
496
488
case mt : MethodType =>
497
489
val outers = outer.args(fun.asInstanceOf [tpd.Tree ]) // can't use fun1 here because its type is already erased
498
- var args0 = protoArgs2 (pt, tree.typeOpt)
499
- if (! mt.isUnusedMethod) args0 = args ::: args0
490
+ var args0 = protoArgs (pt, tree.typeOpt)
491
+ if (mt.paramNames.nonEmpty && ! mt.isUnusedMethod) args0 = args ::: args0
500
492
args0 = outers ::: args0
501
493
502
494
if (args0.length > MaxImplementedFunctionArity && mt.paramInfos.length == 1 ) {
@@ -505,8 +497,10 @@ object Erasure {
505
497
args0 = bunchedArgs :: Nil
506
498
}
507
499
// Arguments are phantom if an only if the parameters are phantom, guaranteed by the separation of type lattices
508
- val args1 = args0.filterConserve(arg => ! wasPhantom(arg.typeOpt)).zipWithConserve(mt.paramInfos)(typedExpr)
509
- untpd.cpy.Apply (tree)(fun1, args1) withType mt.resultType
500
+ val args1 = args0.filterConserve(arg => ! wasPhantom(arg.typeOpt))
501
+ assert(args1 hasSameLengthAs mt.paramInfos)
502
+ val args2 = args1.zipWithConserve(mt.paramInfos)(typedExpr)
503
+ untpd.cpy.Apply (tree)(fun1, args2) withType mt.resultType
510
504
case _ =>
511
505
throw new MatchError (i " tree $tree has unexpected type of function ${fun1.tpe.widen}, was ${fun.typeOpt.widen}" )
512
506
}
0 commit comments