-
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
Refine implicit priority change warnings #21045
Conversation
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.
Otherwise looks right to me 👍
We now miss the following change: trait A[T]
trait B[T] extends A[T]
given b[T]: B[T] = ???
given a[T]: A[T] = ???
val y = summon[A[String]] // changes from `b` in 3.5 to `a` 3.6 as expected but without warning in either |
It seems we really do need to know whether the I guess an alternative solution would be to just disable the filtering of candidates for which |
As worked out in collaboration with @EugeneFlesselle
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.
This was tricky to do efficiently, but we got a good solution after all!
if alt1.ref eq alt2.ref then 0 | ||
else if alt1.level != alt2.level then alt1.level - alt2.level | ||
else | ||
var cmp = comp(using searchContext()) | ||
val sv = Feature.sourceVersion | ||
if sv.stable == SourceVersion.`3.5` || sv == SourceVersion.`3.6-migration` then | ||
if isWarnPriorityChangeVersion(sv) then |
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.
I suppose sv
is constant and isWarnPriorityChangeVersion
could then be a val
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.
No, I use it below as well in the assert that we originally commented out.
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.
Oh, I meant even isWarnPriorityChangeVersion(Feature.sourceVersion)
would be constant between calls of compareAlternatives
. But no big deal either way, this is still ready to merge for me
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.
Yes, but be need sourceVersion as sv
separately in compareAlternatives.
This should be part of 3.5.0 RC4. |
Backports #21045 to 3.5.0-RC4
Backports #21045 to 3.5.1-RC1
On the final result, compared with all the ambiguous candidates we are trying to recover from. We should still use `disambiguate = false` when filtering the `pending` candidates for the purpose of warnings, as in the other cases. Before, we could heal an ambiguous SearchFailure with a candidate which was considered better only under the alternative given prioritization scheme, see scala#21045 for details.
On the final result, compared with all the ambiguous candidates we are trying to recover from. We should still use `disambiguate = false` when filtering the `pending` candidates for the purpose of warnings, as in the other cases. Before, we could heal an ambiguous SearchFailure with a candidate which was considered better only under the alternative given prioritization scheme, see scala#21045 for details.
On the final result, compared with all the ambiguous candidates we are trying to recover from. We should still use `disambiguate = false` when filtering the `pending` candidates for the purpose of warnings, as in the other cases. Before, we could heal an ambiguous SearchFailure with a candidate which was considered better only under the alternative given prioritization scheme, see scala#21045 for details.
On the final result, compared with all the ambiguous candidates we are trying to recover from. We should still use `disambiguate = false` when filtering the `pending` candidates for the purpose of warnings, as in the other cases. Before the changes, it was possible for an ambiguous SearchFailure to be healed by a candidate which was considered better (possibly only) under a prioritization scheme different from the current one. As an optimization, we can avoid redoing compareAlternatives in versions which could have only used the new prioritization scheme to begin with. Also restores behaviour avoiding false positive warnings. Specifically, in cases where we could report a change in prioritization, despite having not yet done `tryImplicit` on the alternative, i.e. it was only compared as part of an early filtering See scala#21045 for related changes
On the final result, compared with all the ambiguous candidates we are trying to recover from. We should still use `disambiguate = false` when filtering the `pending` candidates for the purpose of warnings, as in the other cases. Before the changes, it was possible for an ambiguous SearchFailure to be healed by a candidate which was considered better (possibly only) under a prioritization scheme different from the current one. As an optimization, we can avoid redoing compareAlternatives in versions which could have only used the new prioritization scheme to begin with. Also restores behaviour avoiding false positive warnings. Specifically, in cases where we could report a change in prioritization, despite having not yet done `tryImplicit` on the alternative, i.e. it was only compared as part of an early filtering See scala#21045 for related changes
Based on #21328: We now use a left-biased scheme, as follows. From 3.7 on: A given x: X is better than a given or implicit y: Y if y can be instantiated/widened to X. An implicit x: X is better than a given or implicit y: Y if y can be instantiated to a supertype of X. Use owner score for givens as a tie breaker if after all other tests we still have an ambiguity. This is not transitive, but the PR implements a scheme to work around that. Other changes: - Drop special handling of NotGiven in prioritization. The previous logic pretended to do so, but was ineffective. - Fix healAmbiguous to compareAlternatives with disambiguate = true, to account for changes made in #21045
On the final result, compared with all the ambiguous candidates we are trying to recover from. We should still use `disambiguate = false` when filtering the `pending` candidates for the purpose of warnings, as in the other cases. Before the changes, it was possible for an ambiguous SearchFailure to be healed by a candidate which was considered better (possibly only) under a prioritization scheme different from the current one. As an optimization, we can avoid redoing compareAlternatives in versions which could have only used the new prioritization scheme to begin with. Also restores behaviour avoiding false positive warnings. Specifically, in cases where we could report a change in prioritization, despite having not yet done `tryImplicit` on the alternative, i.e. it was only compared as part of an early filtering See scala#21045 for related changes
On the final result, compared with all the ambiguous candidates we are trying to recover from. We should still use `disambiguate = false` when filtering the `pending` candidates for the purpose of warnings, as in the other cases. Before the changes, it was possible for an ambiguous SearchFailure to be healed by a candidate which was considered better (possibly only) under a prioritization scheme different from the current one. As an optimization, we can avoid redoing compareAlternatives in versions which could have only used the new prioritization scheme to begin with. Also restores behaviour avoiding false positive warnings. Specifically, in cases where we could report a change in prioritization, despite having not yet done `tryImplicit` on the alternative, i.e. it was only compared as part of an early filtering See scala#21045 for related changes
Fixes #21036
Fixes #20572