@@ -446,13 +446,13 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
446
446
* inline annotations from their parameters. The generated `def` is appended
447
447
* to `bindingsBuf`.
448
448
* @param name the name of the parameter
449
- * @param paramtp the type of the parameter
449
+ * @param formal the type of the parameter
450
450
* @param arg the argument corresponding to the parameter
451
451
* @param bindingsBuf the buffer to which the definition should be appended
452
452
*/
453
- private def paramBindingDef (name : Name , paramtp : Type , arg0 : Tree ,
453
+ private def paramBindingDef (name : Name , formal : Type , arg0 : Tree ,
454
454
bindingsBuf : mutable.ListBuffer [ValOrDefDef ])(using Context ): ValOrDefDef = {
455
- val isByName = paramtp .dealias.isInstanceOf [ExprType ]
455
+ val isByName = formal .dealias.isInstanceOf [ExprType ]
456
456
val arg = arg0 match {
457
457
case Typed (arg1, tpt) if tpt.tpe.isRepeatedParam && arg1.tpe.derivesFrom(defn.ArrayClass ) =>
458
458
wrapArray(arg1, arg0.tpe.elemType)
@@ -461,19 +461,19 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
461
461
val argtpe = arg.tpe.dealiasKeepAnnots.translateFromRepeated(toArray = false )
462
462
val argIsBottom = argtpe.isBottomTypeAfterErasure
463
463
val bindingType =
464
- if argIsBottom then paramtp
464
+ if argIsBottom then formal
465
465
else if isByName then ExprType (argtpe.widen)
466
466
else argtpe.widen
467
467
var bindingFlags : FlagSet = InlineProxy
468
- if paramtp .widenExpr.hasAnnotation(defn.InlineParamAnnot ) then
468
+ if formal .widenExpr.hasAnnotation(defn.InlineParamAnnot ) then
469
469
bindingFlags |= Inline
470
470
if isByName then
471
471
bindingFlags |= Method
472
472
val boundSym = newSym(InlineBinderName .fresh(name.asTermName), bindingFlags, bindingType).asTerm
473
473
val binding = {
474
474
var newArg = arg.changeOwner(ctx.owner, boundSym)
475
475
if bindingFlags.is(Inline ) && argIsBottom then
476
- newArg = Typed (newArg, TypeTree (paramtp )) // type ascribe RHS to avoid type errors in expansion. See i8612.scala
476
+ newArg = Typed (newArg, TypeTree (formal )) // type ascribe RHS to avoid type errors in expansion. See i8612.scala
477
477
if isByName then DefDef (boundSym, newArg)
478
478
else ValDef (boundSym, newArg)
479
479
}.withSpan(boundSym.span)
@@ -487,30 +487,28 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
487
487
* proxies to this-references. Issue an error if some arguments are missing.
488
488
*/
489
489
private def computeParamBindings (
490
- tp : Type , targs : List [Tree ], argss : List [List [Tree ]], paramSubst : Type => Type ): Boolean =
490
+ tp : Type , targs : List [Tree ], argss : List [List [Tree ]], formalss : List [ List [ Type ]] ): Boolean =
491
491
tp match
492
492
case tp : PolyType =>
493
493
tp.paramNames.lazyZip(targs).foreach { (name, arg) =>
494
494
paramSpan(name) = arg.span
495
495
paramBinding(name) = arg.tpe.stripTypeVar
496
496
}
497
- computeParamBindings(
498
- tp.resultType, targs.drop(tp.paramNames.length), argss,
499
- paramSubst.andThen(_.substParams(tp, targs.map(_.tpe.stripTypeVar))))
497
+ computeParamBindings(tp.resultType, targs.drop(tp.paramNames.length), argss, formalss)
500
498
case tp : MethodType =>
501
499
if argss.isEmpty then
502
500
report.error(i " missing arguments for inline method $inlinedMethod" , call.srcPos)
503
501
false
504
502
else
505
- tp.paramNames.lazyZip(tp.paramInfos ).lazyZip(argss.head).foreach { (name, paramtp , arg) =>
503
+ tp.paramNames.lazyZip(formalss.head ).lazyZip(argss.head).foreach { (name, formal , arg) =>
506
504
paramSpan(name) = arg.span
507
505
paramBinding(name) = arg.tpe.dealias match
508
506
case _ : SingletonType if isIdempotentPath(arg) =>
509
507
arg.tpe
510
508
case _ =>
511
- paramBindingDef(name, paramSubst(paramtp) , arg, bindingsBuf).symbol.termRef
509
+ paramBindingDef(name, formal , arg, bindingsBuf).symbol.termRef
512
510
}
513
- computeParamBindings(tp.resultType, targs, argss.tail, paramSubst )
511
+ computeParamBindings(tp.resultType, targs, argss.tail, formalss.tail )
514
512
case _ =>
515
513
assert(targs.isEmpty)
516
514
assert(argss.isEmpty)
@@ -698,8 +696,16 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
698
696
)
699
697
}
700
698
699
+ def paramTypess (call : Tree , acc : List [List [Type ]]): List [List [Type ]] = call match
700
+ case Apply (fn, args) =>
701
+ fn.tpe.widen.match
702
+ case mt : MethodType => paramTypess(fn, mt.instantiateParamInfos(args.tpes) :: acc)
703
+ case _ => Nil
704
+ case TypeApply (fn, _) => paramTypess(fn, acc)
705
+ case _ => acc
706
+
701
707
// Compute bindings for all parameters, appending them to bindingsBuf
702
- if ! computeParamBindings(inlinedMethod.info, callTypeArgs, callValueArgss, identity ) then
708
+ if ! computeParamBindings(inlinedMethod.info, callTypeArgs, callValueArgss, paramTypess(call, Nil ) ) then
703
709
return call
704
710
705
711
// make sure prefix is executed if it is impure
0 commit comments