Skip to content

Commit ac1250b

Browse files
committed
Fuse addTyped and addTypedAndSubstitute
1 parent c5e4942 commit ac1250b

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -533,19 +533,17 @@ trait Applications extends Compatibility {
533533
case formal :: formals1 =>
534534

535535
/** Add result of typing argument `arg` against parameter type `formal`.
536-
* @return A type transformation to apply to all arguments following this one.
536+
* @return The remaining formal parameter types. If the method is parameter-dependent
537+
* this means substituting the actual argument type for the current formal parameter
538+
* in the remaining formal parameters.
537539
*/
538-
def addTyped(arg: Arg, formal: Type): Type => Type = {
540+
def addTyped(arg: Arg, formal: Type): List[Type] =
539541
addArg(typedArg(arg, formal), formal)
540-
if (methodType.isParamDependent && typeOfArg(arg).exists)
542+
if methodType.isParamDependent && typeOfArg(arg).exists then
541543
// `typeOfArg(arg)` could be missing because the evaluation of `arg` produced type errors
542-
safeSubstParam(_, methodType.paramRefs(n), typeOfArg(arg))
543-
else identity
544-
}
545-
546-
def addTypedAndSubstitute(arg: Arg, formal: Type): List[Type] =
547-
val substParam = addTyped(arg, formal)
548-
formals1.mapconserve(substParam)
544+
formals1.mapconserve(safeSubstParam(_, methodType.paramRefs(n), typeOfArg(arg)))
545+
else
546+
formals1
549547

550548
def missingArg(n: Int): Unit = {
551549
val pname = methodType.paramNames(n)
@@ -587,11 +585,11 @@ trait Applications extends Compatibility {
587585
def implicitArg = implicitArgTree(formal, appPos.span)
588586

589587
if methodType.isContextualMethod && ctx.mode.is(Mode.ImplicitsEnabled) then
590-
matchArgs(args1, addTypedAndSubstitute(treeToArg(implicitArg), formal), n + 1)
588+
matchArgs(args1, addTyped(treeToArg(implicitArg), formal), n + 1)
591589
else
592590
val defaultArg = defaultExpr
593591
if !defaultArg.isEmpty then
594-
matchArgs(args1, addTypedAndSubstitute(treeToArg(defaultArg), formal), n + 1)
592+
matchArgs(args1, addTyped(treeToArg(defaultArg), formal), n + 1)
595593
else
596594
missingArg(n)
597595
}
@@ -613,7 +611,7 @@ trait Applications extends Compatibility {
613611
case EmptyTree :: args1 =>
614612
tryDefault(n, args1)
615613
case arg :: args1 =>
616-
matchArgs(args1, addTypedAndSubstitute(arg, formal), n + 1)
614+
matchArgs(args1, addTyped(arg, formal), n + 1)
617615
case nil =>
618616
tryDefault(n, args)
619617
}

0 commit comments

Comments
 (0)