-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Regression in implicit search in mixed implicit/givens sources #21264
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
Comments
Related issue found in OpenCB build. trait Context
class AutoDerivationMacro extends Reflection:
implicit val context: Context = ???
def usage = summon[Context] // error
trait Reflection:
given Context = context
val context: Context yields warnings under -source:3.5 or errors in 3.6+: [warn] ./src/main/scala/test.scala:4:30
[warn] Given search preference for Context between alternatives (AutoDerivationMacro.this.context : Context) and (AutoDerivationMacro.this.given_Context : Context) will change
[warn] Current choice : the first alternative
[warn] New choice from Scala 3.6: none - it's ambiguous
[warn] def usage = summon[Context] // error
[warn] ^ I belive a change to mitigate this issue in compiler codebase was done in the PR introducing the change |
The issue seems to affect currently 17 projects in the Open CB:
|
OK, looking at the original code before #21226 it looks to me that unless one of the participants was the So this means the only given to de-prioritize is in fact |
While we are at it. Can we get rid of if Feature.sourceVersion.isAtMost(SourceVersion.`3.4`)
|| oldResolution
|| alt1IsImplicit && alt2IsImplicit
then
// Intermediate rules: better means specialize, but map all type arguments downwards
// These are enabled for 3.0-3.5, and for all comparisons between old-style implicits,
// and in 3.5 and 3.6-migration when we compare with previous rules. This test is now problematic since it violates the transitivity requirement. If we have a given G and implicits I1, I2 with Previously this was not deemed a problem because we thought that the given G would always be picked over both I1 and I2. But that assumption was in fact false, because of the typo in |
This holds only in the case where alt1.symbol.is(Given) && (alt1.symbol != defn.NotGivenClass) != (alt2.symbol != defn.NotGivenClass) Which means there was even less of a difference and I would hence very much agree with
EDIT: even though if alt1.symbol.is(Implicit) then old-style implicit comparison scheme between alts
else
if (both alts are NotGivenClass) then old-style implicit comparison scheme between alts
else if (neither alts are NotGivenClass) then new-style implicit comparison scheme between alts
else the NotGivenClass alt loses |
Making sure I understood correctly, this is now (after #21226) fixed right ? |
I don't see why not, I'll try it out |
Correct. |
But make a separate commit, so we can roll easily back of openCB chokes up. |
I verified that both problems mentioned here will go away with #21305. |
We went through a number of iterations (#21305, #21328, #21339) to mitigate the changes in resolution, which were warned about when compiling with I can confirm the original test case tests/pos/not-looping-implicit.scala for which this issue was opened is behaving as excepted (no warnings generated) for all source versions. |
I believe we can close it as completed. |
Extracted from discussion in #21226 introducing problems
I'll start the OpenCB to check it on the bigger number of codebases
Originally posted by @WojciechMazur in #21226 (comment)
Originally posted by @odersky in #21226 (comment)
The text was updated successfully, but these errors were encountered: