commit 2ae9e06363b294f60b62e765d31fce4417e14a9d (tree)
parent e61e8c94beba912400b71891d8bfcfa9c1c1d837
Author: Veikka Tuominen <git@vexu.eu>
Date: Wed, 27 May 2020 17:00:31 +0300
Merge pull request #5448 from Vexu/translate-c
Translate-c use correct scope in for loop condition
Diffstat:
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git 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
@@ -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;
+ \\}
+ ,"");
}