Skip to content

Commit 55d7300

Browse files
committed
Change order of default and implicit attempts
In a using argument clause with missing arguments: - resolve to defaults first, - only if that fails, do an implicit argument search. This is the same as if all implicit parameters `x: T` that did not have an explicit default now are given one like this: x: T = summon[T]
1 parent ac1250b commit 55d7300

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ trait Applications extends Compatibility {
555555
def tryDefault(n: Int, args1: List[Arg]): Unit = {
556556
val sym = methRef.symbol
557557

558-
def defaultExpr =
558+
val defaultArg =
559559
if (isJavaAnnotConstr(sym)) {
560560
val cinfo = sym.owner.asClass.classInfo
561561
val pname = methodType.paramNames(n)
@@ -584,14 +584,12 @@ trait Applications extends Compatibility {
584584

585585
def implicitArg = implicitArgTree(formal, appPos.span)
586586

587-
if methodType.isContextualMethod && ctx.mode.is(Mode.ImplicitsEnabled) then
587+
if !defaultArg.isEmpty then
588+
matchArgs(args1, addTyped(treeToArg(defaultArg), formal), n + 1)
589+
else if methodType.isContextualMethod && ctx.mode.is(Mode.ImplicitsEnabled) then
588590
matchArgs(args1, addTyped(treeToArg(implicitArg), formal), n + 1)
589591
else
590-
val defaultArg = defaultExpr
591-
if !defaultArg.isEmpty then
592-
matchArgs(args1, addTyped(treeToArg(defaultArg), formal), n + 1)
593-
else
594-
missingArg(n)
592+
missingArg(n)
595593
}
596594

597595
if (formal.isRepeatedParam)

0 commit comments

Comments
 (0)