-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Name clash causes wrong implicit to be selected #18183
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
https://docs.scala-lang.org/scala3/reference/changed-features/implicit-resolution.html says:
so it's potentially fair game for the code to behave differently than in 2. It then goes on to say:
and there is no further language about what exactly this means. There is some language describing an example consequence of the change:
but this is only illustrative. So we're left with only "Nesting is now taken into account", which is realllllllllllly vague. The language here is so vague that I don't think we can say for sure what outcome was intended here. There are three possible outcomes:
I agree that 1 is surprising and seems wrong. I can see arguing for either 2 (the Scala 2 behavior) or 3, but I can't see what the design justification for 1 (the current behavior) could be. |
Dale has found #8092, which seems to be the same issue, and where Bjorn's expectations matched mine. Now reading through that, and #17809, to try to understand the justification. (There, we see that Michał also found the current behavior puzzling.) cc @som-snytt |
I see that #17809 remains unresolved, and that none of us seem to fully understand Martin's remark on the subject. 🤷 |
per the old odersky remark, imports introduce a context, so that's why the nesting rule lends them priority. I agree that it's a bit mind bending. I was just looking at a Scala 2 issue about imports and realized that the mechanics are quite subtle. (I mean the internal dance between namer and typer.) I think it's OK to ask the user to have a "mental model" about contexts, which are loosely associated with braces. |
This looks indeed like a bug. |
Instead of Marshall McLuhan in the Woody Allen movie, it's odersky. |
Uh oh!
There was an error while loading. Please reload this page.
Compiler version
3.3.0
Minimized code
Output
Expectation
I don't expect the wrong implicit to be selected.
The name clash is part of the cause here. With a different name, I expected the more locally defined implicit to win over the wildcard imported one, but that in situation they're actually ambiguous - which is not ideal but it is a little better.
Unimporting, i.e.
import bar.{ foo => _, _ }
is a workaround.Also, it works correctly in Scala 2.
The text was updated successfully, but these errors were encountered: