Skip to content

Commit 7468f25

Browse files
committed
Filter out default arguments in issueErrors directly
1 parent 292865a commit 7468f25

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3850,22 +3850,29 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
38503850

38513851
val args = implicitArgs(wtp.paramInfos, 0, pt)
38523852

3853-
def issueErrors(failingArgs: List[Tree]): Tree = {
3854-
val firstNonAmbiguous = failingArgs.tpes.find(tp => tp.isError && !tp.isInstanceOf[AmbiguousImplicits])
3855-
def firstError = failingArgs.tpes.find(_.isError)
3856-
val propFail = firstNonAmbiguous.orElse(firstError).getOrElse(NoType)
3857-
3858-
def paramSymWithMethodTree(paramName: TermName) =
3853+
def issueErrors(): Tree = {
3854+
val paramSyms =
38593855
if tree.symbol.exists then
38603856
tree.symbol.paramSymss.flatten
38613857
.map(sym => sym.name -> sym)
38623858
.toMap
3863-
.get(paramName)
3864-
.map((_, tree))
38653859
else
3866-
None
3860+
Map.empty
3861+
3862+
def paramSymWithMethodTree(paramName: TermName) = paramSyms.get(paramName).map((_, tree))
3863+
def paramHasDefault(paramName: TermName) = paramSyms.get(paramName).map(_.is(HasDefault)).getOrElse(false)
3864+
3865+
val nonDefaultArgs: List[Tree] =
3866+
wtp.paramNames
3867+
.lazyZip(args)
3868+
.filter((paramName, arg) => !paramHasDefault(paramName))
3869+
.map(((paramName, arg) => arg))
3870+
3871+
var firstNonAmbiguous = nonDefaultArgs.tpes.find(tp => tp.isError && !tp.isInstanceOf[AmbiguousImplicits])
3872+
def firstError = nonDefaultArgs.tpes.find(_.isError)
3873+
val propFail: Type = firstNonAmbiguous.orElse(firstError).getOrElse(NoType)
38673874

3868-
wtp.paramNames.lazyZip(wtp.paramInfos).lazyZip(failingArgs).foreach { (paramName, formal, arg) =>
3875+
wtp.paramNames.lazyZip(wtp.paramInfos).lazyZip(nonDefaultArgs).foreach { (paramName, formal, arg) =>
38693876
arg.tpe match {
38703877
case failure: SearchFailureType =>
38713878
report.error(
@@ -3875,7 +3882,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
38753882
case _ =>
38763883
}
38773884
}
3878-
untpd.Apply(tree, failingArgs).withType(propFail)
3885+
untpd.Apply(tree, args).withType(propFail)
38793886
}
38803887

38813888
if (args.tpes.exists(_.isError)) {
@@ -3890,19 +3897,17 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
38903897
// implicits are passed as named args.
38913898
if hasDefaultParams then
38923899
val namedArgs = wtp.paramNames.lazyZip(args).flatMap { (pname, arg) =>
3893-
if arg.tpe.isInstanceOf[NoMatchingImplicits] then Nil
3894-
else untpd.NamedArg(pname, untpd.TypedSplice(arg)) :: Nil
3900+
if arg.tpe.isError then Nil else untpd.NamedArg(pname, untpd.TypedSplice(arg)) :: Nil
38953901
}
38963902
val app = cpy.Apply(tree)(untpd.TypedSplice(tree), namedArgs)
38973903
val needsUsing = wtp.isContextualMethod || wtp.match
38983904
case MethodType(ContextBoundParamName(_) :: _) => sourceVersion.isAtLeast(`3.4`)
38993905
case _ => false
39003906
if needsUsing then app.setApplyKind(ApplyKind.Using)
39013907
typr.println(i"try with default implicit args $app")
3902-
val tpdApply @ Apply(_, args1) = typed(app, pt, locked): @unchecked
3903-
println("tpdApply.tpe " + tpdApply.tpe)
3904-
if tpdApply.tpe.isError then issueErrors(args1) else tpdApply
3905-
else issueErrors(args)
3908+
val tpdApply = typed(app, pt, locked)
3909+
if tpdApply.tpe.isError then issueErrors() else tpdApply
3910+
else issueErrors()
39063911
}
39073912
else tree match {
39083913
case tree: Block =>

0 commit comments

Comments
 (0)