Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport "Avoid cyclic errors forcing default arg types" to LTS #22139

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -625,6 +625,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 = ???
}
Loading