motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit cd5b7b9e1d56b22bc2267d5d94acec8d21c29110 (tree)
parent b6e1670d2ba1e7724878ee2b7176077da5cb7c35
Author: Vexu <git@vexu.eu>
Date:   Wed, 27 May 2020 01:19:55 +0300

translate-c: use correct scope in for loop condition

Diffstat:
Msrc-self-hosted/translate_c.zig | 2+-
Mtest/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 @@ -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; + \\} + ,""); }