stage2: variable shadowing detection #6969
Conversation
|
Nice. |
|
This implementation has the same two-step scope lookup as stage1, including the flaw noticed in #7141. |
|
I just used the logic from the identifier resolution code here, so if we want to implement the more "advanced" lookup logic we should probably abstract it into a "lookup" function and then use it in both places. |
|
It's not a "basic" vs "more advanced" thing, it's a "according to the specification" vs "stage1's behaviour" case. |
|
The problem with stage1 is that declarations only look for redefinitions in the same container, not with local variables. |
|
The logic looks OK to me here. Let me clarify the language specification (cc @SpexGuy): Declarations are allowed to collide, so that it is possible to declare, for example, both of these:
pub const a = struct {
pub const b = struct {
pub const c = struct {};
};
pub const c = struct {};
};This is allowed, however, ambiguous references to Parameters and local variables are never allowed to shadow anything, including each other, or any declarations, no exceptions. |
|
So, if I understand correctly your example, #7140 is legal but the use of |
|
Yes |
This allows detection of variable shadowing in stage2, fixing a TODO in
varDeclfunction. I added acompileErrortest to test/stage2/test.zig, but it didn't seem to run.Edit:
The test actually did run and pass, but it said that it ran the wrong number of tests?
Why does it say 1/17 and 1/28? and then only 17 tests pass? I think this is a bug in the testing code.