diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index c6d8fd80fd60..05c890f504a3 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -696,6 +696,10 @@ trait Applications extends Compatibility { fail(MissingArgument(methodType.paramNames(n), methString)) def tryDefault(n: Int, args1: List[Arg]): Unit = { + if !success then + missingArg(n) // fail fast before forcing the default arg tpe, to avoid cyclic errors + return + val sym = methRef.symbol val testOnly = this.isInstanceOf[TestApplication[?]] diff --git a/tests/neg/19414-desugared.check b/tests/neg/19414-desugared.check index c21806e16c2c..cc51ee471553 100644 --- a/tests/neg/19414-desugared.check +++ b/tests/neg/19414-desugared.check @@ -8,7 +8,6 @@ | writer = | /* ambiguous: both given instance given_Writer_JsValue and given instance given_Writer_JsObject match type Writer[B] */ | summon[Writer[B]] - | , - | this.given_BodySerializer_B$default$2[B]) + | ) | |But both given instance given_Writer_JsValue and given instance given_Writer_JsObject match type Writer[B]. diff --git a/tests/neg/19414.check b/tests/neg/19414.check index 6804546df037..016e3942c825 100644 --- a/tests/neg/19414.check +++ b/tests/neg/19414.check @@ -8,7 +8,6 @@ | evidence$1 = | /* ambiguous: both given instance given_Writer_JsValue and given instance given_Writer_JsObject match type Writer[B] */ | summon[Writer[B]] - | , - | this.given_BodySerializer_B$default$2[B]) + | ) | |But both given instance given_Writer_JsValue and given instance given_Writer_JsObject match type Writer[B]. diff --git a/tests/neg/given-ambiguous-default-2.check b/tests/neg/given-ambiguous-default-2.check index cbe8b972a389..4d473a301340 100644 --- a/tests/neg/given-ambiguous-default-2.check +++ b/tests/neg/given-ambiguous-default-2.check @@ -1,9 +1,9 @@ -- [E172] Type Error: tests/neg/given-ambiguous-default-2.scala:18:23 -------------------------------------------------- 18 |def f: Unit = summon[C] // error: Ambiguous given instances | ^ - |No best given instance of type C was found for parameter x of method summon in object Predef. - |I found: + | No best given instance of type C was found for parameter x of method summon in object Predef. + | I found: | - | given_C(a = /* ambiguous: both given instance a1 and given instance a2 match type A */summon[A], this.given_C$default$2) + | given_C(a = /* ambiguous: both given instance a1 and given instance a2 match type A */summon[A]) | - |But both given instance a1 and given instance a2 match type A. + | But both given instance a1 and given instance a2 match type A. diff --git a/tests/pos/i21568.scala b/tests/pos/i21568.scala new file mode 100644 index 000000000000..87184956ea79 --- /dev/null +++ b/tests/pos/i21568.scala @@ -0,0 +1,6 @@ +class Lang(name: String) +object Lang { + val Default = Lang("") + def apply(language: String): Lang = ??? + def apply(maybeLang: Option[String], default: Lang = Default): Lang = ??? +}