-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Don't try default args when there are ambiguous implicits #19647
Conversation
|
||
val propFail = propagatedFailure(args) | ||
val firstAmbiguous = args.tpes.find(_.isInstanceOf[AmbiguousImplicits]) | ||
def firstError = args.tpes.find(_.isError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now traversing args
twice in the worst case, but I think the readability gain is worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: as before, I am only checking for AmbiguousImplicits
. Should TooUnspecific
fall in the same case? I am asking because both are considered ambiguous
here:
Before this commit, the logic in `class Typer` / `def adapt1` / `def addImplicitArgs` was to try default arguments if *any* argument had an implicit search error that was not an ambiguous implicits error. This commit changes the logic to try default arguments only if *all* arguments' implicit search errors are not ambiguous implicits error. The rational is that if there is any ambiguous implicits error, it's not worth trying default arguments because this cannot solve the ambiguity. Instead, we report the first ambiguous implicits error directly.
val propFail = propagatedFailure(args) | ||
val firstAmbiguous = args.tpes.find(_.isInstanceOf[AmbiguousImplicits]) | ||
def firstError = args.tpes.find(_.isError) | ||
val propFail = firstAmbiguous.orElse(firstError).getOrElse(NoType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the previous logic preferred non-ambiguity errors over ambiguity errors, and this PR changes it to prefer ambiguity errors over non-ambiguity errors, but since ambiguity is no longer special after https://dotty.epfl.ch/docs/reference/changed-features/implicit-resolution.html, perhaps we could just report the first error found? /cc @odersky
Superseded by #20261. |
Fixes #19414.