diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig index 68c70d8db6..29bcddc5f2 100644 --- a/src-self-hosted/translate_c.zig +++ b/src-self-hosted/translate_c.zig @@ -2515,7 +2515,7 @@ fn transForLoop( } var cond_scope = Scope.Condition{ .base = .{ - .parent = scope, + .parent = &loop_scope, .id = .Condition, }, }; diff --git a/test/run_translated_c.zig b/test/run_translated_c.zig index 7dc64f068f..c7f7c2c5c6 100644 --- a/test/run_translated_c.zig +++ b/test/run_translated_c.zig @@ -256,4 +256,17 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void { \\ return 0; \\} , ""); + + cases.add("scoped for loops with shadowing", + \\#include + \\int main() { + \\ int count = 0; + \\ for (int x = 0; x < 2; x++) + \\ for (int x = 0; x < 2; x++) + \\ count++; + \\ + \\ if (count != 4) abort(); + \\ return 0; + \\} + ,""); }