-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix: resolve extern prelude for local mods in block modules #17251
Conversation
I'm not sure how to add unittests for it. 🤔 |
if self.block.is_some() { | ||
// Don't resolve extern prelude in block `DefMap`s, defer it to the crate def map so | ||
// that blocks can properly shadow them | ||
if matches!(self[module].origin, ModuleOrigin::BlockExpr { .. }) { |
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.
if matches!(self[module].origin, ModuleOrigin::BlockExpr { .. }) { | |
if self.block.is_some() && module == DefMap::ROOT { |
If I understand the code here correctly, likjewise below. Though I am unsure whether this is the correct fix here
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.
Though it should be more correct than the status quo
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.
They are equivalent. If a module is a BlockExpr
, its local_id
should be equivalent to ROOT
, and it should be within a block; conversely, this is also true. Should I change it to the latter?
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, sorry I wasn't clear. With unsure whether this is the correct fix I meant the general approach here. My code suggestion is the more correct way to do your check here (they are equivalent, it's just that the origin shouldn't be used to check this property).
if matches!(self[module].origin, ModuleOrigin::BlockExpr { .. }) { | ||
// Don't resolve extern prelude in pseudo-module of a block. |
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.
Same thing here
Thanks! |
@bors r+ |
☀️ Test successful - checks-actions |
fix: do not resolve prelude within block modules fix #17338 (continuing from #17251). In #17251, we injected preludes into non-top-level modules, which leading to r-a to directly resolve names in preludes in block modules. This PR fix it by checking whether the module is a pseudo-module introduced by blocks. (similar to what we do for extern preludes)
fix #17057, #17032.
We should use
ModuleOrigin
to check if the current module is a pseudo-module introduced by blocks (where names might be shadowed), rather than checkingblock_def_map
.