zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 82273f1a2a3bf3d90e24c3aeb77fbcdafdc82872 (tree)
parent 400d8d0b82b5f0aa7afe0ac8e4776daa8ebbac31
Author: Tadeo Kondrak <me@tadeo.ca>
Date:   Mon, 31 Aug 2020 01:01:43 -0600

translate_c: fix shadowing on nested blocks

Diffstat:
Msrc-self-hosted/translate_c.zig | 2+-
Mtest/run_translated_c.zig | 17+++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig @@ -168,7 +168,7 @@ const Scope = struct { fn localContains(scope: *Block, name: []const u8) bool { for (scope.variables.items) |p| { - if (mem.eql(u8, p.name, name)) + if (mem.eql(u8, p.alias, name)) return true; } return false; diff --git a/test/run_translated_c.zig b/test/run_translated_c.zig @@ -3,6 +3,23 @@ const tests = @import("tests.zig"); const nl = std.cstr.line_sep; pub fn addCases(cases: *tests.RunTranslatedCContext) void { + cases.add("variable shadowing type type", + \\#include <stdlib.h> + \\int main() { + \\ int type = 1; + \\ if (type != 1) abort(); + \\} + , ""); + + cases.add("assignment as expression", + \\#include <stdlib.h> + \\int main() { + \\ int a, b, c, d = 5; + \\ int e = a = b = c = d; + \\ if (e != 5) abort(); + \\} + , ""); + cases.add("static variable in block scope", \\#include <stdlib.h> \\int foo() {