Skip to content

Commit

Permalink
Avoid cyclic errors forcing default arg types
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Sep 16, 2024
1 parent ad8c21a commit 59fd35f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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[?]]

Expand Down
3 changes: 1 addition & 2 deletions tests/neg/19414-desugared.check
Original file line number Diff line number Diff line change
Expand Up @@ -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].
3 changes: 1 addition & 2 deletions tests/neg/19414.check
Original file line number Diff line number Diff line change
Expand Up @@ -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].
8 changes: 4 additions & 4 deletions tests/neg/given-ambiguous-default-2.check
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions tests/pos/i21568.scala
Original file line number Diff line number Diff line change
@@ -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 = ???
}

0 comments on commit 59fd35f

Please sign in to comment.