-
Notifications
You must be signed in to change notification settings - Fork 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
repl - new heuristic for import shadowing #14951
Conversation
Previously, the challenge was not in selecting named things, but detecting whether an import is needed for implicit resolution. |
@som-snytt could you elaborate why implicit resolution is a problem here ? |
I still haven't had a chance to read this PR, which I look forward to, but to explain my comment: If I Apologies in advance if that issue has nothing to do with this PR. It came up in every discussion, such as Ammonite, on how REPL imports should work. |
The solution here is complicated enough that it makes me wonder if it's worth it. (Worth the sum of all the future maintenance cost.) Dale suggested maybe just forbidding mixing It also occurred to both of us that another solution path could be to notice when |
This would fix your "import shadowing should only work on toplevel definitions" cases too, I believe. |
ce5d528
to
d2a2198
Compare
d2a2198
to
7901cb8
Compare
Is this something that is still waiting on another review or something that can be pushed forward? |
I'm closing this as both Dale and Seths idea seems to be a better way to solve this issue. |
Fixes #5074
Link to previous fix discussions: #4915
The main point of this pull request is changing how we handle imports in the following repl evaluations.
On the contrary to the compiler, repl should allow definition shadowing by imports and vice-versa.
The previous heuristic was handling only one-way shadowing which was the result of import handling in the following way:
import rs$line${i <- 0 until nextId}._
It could handle shadowing, when import shadowed the definition:
However, this couldn't work the way around as top-level imports are imported after wrapper:
The new proposed heuristic works in the following way:
We only need to check forward references as import handling in the following object stays the same (the first wrapper, then import ) hence all definitions which were defined before the import will be shadowed anyway.
for each intersection member we transform the import by prepending its exclusion ( ImportSelector(Ident(name), Ident(Wildcard)) to existing selectors.