diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig index 888d21db9..b333d24c5 100644 --- 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 index 2b27e3085..35f15eed4 100644 --- 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 + \\int main() { + \\ int type = 1; + \\ if (type != 1) abort(); + \\} + , ""); + + cases.add("assignment as expression", + \\#include + \\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 \\int foo() {