Commit cd5b7b9e1d

Vexu <git@vexu.eu>
2020-05-27 00:19:55
translate-c: use correct scope in for loop condition
1 parent b6e1670
Changed files (2)
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,
         },
     };
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 <stdlib.h>
+        \\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;
+        \\}
+    ,"");
 }