Skip to content

Commit 06b6c96

Browse files
Backport "Avoid cyclic errors forcing default arg types" to LTS (#22139)
Backports #21597 to the 3.3.5. PR submitted by the release tooling. [skip ci]
2 parents 64c2968 + 3febab3 commit 06b6c96

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

Diff for: compiler/src/dotty/tools/dotc/typer/Applications.scala

+4
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,10 @@ trait Applications extends Compatibility {
625625
fail(MissingArgument(methodType.paramNames(n), methString))
626626

627627
def tryDefault(n: Int, args1: List[Arg]): Unit = {
628+
if !success then
629+
missingArg(n) // fail fast before forcing the default arg tpe, to avoid cyclic errors
630+
return
631+
628632
val sym = methRef.symbol
629633
val testOnly = this.isInstanceOf[TestApplication[?]]
630634

Diff for: tests/neg/19414-desugared.check

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
| writer =
99
| /* ambiguous: both given instance given_Writer_JsValue and given instance given_Writer_JsObject match type Writer[B] */
1010
| summon[Writer[B]]
11-
| ,
12-
| this.given_BodySerializer_B$default$2[B])
11+
| )
1312
|
1413
|But both given instance given_Writer_JsValue and given instance given_Writer_JsObject match type Writer[B].

Diff for: tests/neg/19414.check

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
| evidence$1 =
99
| /* ambiguous: both given instance given_Writer_JsValue and given instance given_Writer_JsObject match type Writer[B] */
1010
| summon[Writer[B]]
11-
| ,
12-
| this.given_BodySerializer_B$default$2[B])
11+
| )
1312
|
1413
|But both given instance given_Writer_JsValue and given instance given_Writer_JsObject match type Writer[B].

Diff for: tests/neg/given-ambiguous-default-2.check

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
-- [E172] Type Error: tests/neg/given-ambiguous-default-2.scala:18:23 --------------------------------------------------
22
18 |def f: Unit = summon[C] // error: Ambiguous given instances
33
| ^
4-
|No best given instance of type C was found for parameter x of method summon in object Predef.
5-
|I found:
4+
| No best given instance of type C was found for parameter x of method summon in object Predef.
5+
| I found:
66
|
7-
| given_C(a = /* ambiguous: both given instance a1 and given instance a2 match type A */summon[A], this.given_C$default$2)
7+
| given_C(a = /* ambiguous: both given instance a1 and given instance a2 match type A */summon[A])
88
|
9-
|But both given instance a1 and given instance a2 match type A.
9+
| But both given instance a1 and given instance a2 match type A.

Diff for: tests/pos/i21568.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Lang(name: String)
2+
object Lang {
3+
val Default = Lang("")
4+
def apply(language: String): Lang = ???
5+
def apply(maybeLang: Option[String], default: Lang = Default): Lang = ???
6+
}

0 commit comments

Comments
 (0)