From cd5b7b9e1d56b22bc2267d5d94acec8d21c29110 Mon Sep 17 00:00:00 2001 From: Vexu Date: Wed, 27 May 2020 01:19:55 +0300 Subject: [PATCH] translate-c: use correct scope in for loop condition --- src-self-hosted/translate_c.zig | 2 +- test/run_translated_c.zig | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig index 68c70d8db6f2aa52f88a18589c703138fcefab16..29bcddc5f224002c4c62a29292f08b13e55679c6 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 7dc64f068fed283e00f7b4633e7f7b5443942de3..c7f7c2c5c66f90e4147d3ed2255a8a6535c1d2c8 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; + \\} + ,""); } -- 2.54.0