authorgravatar for me@tadeo.caTadeo Kondrak <me@tadeo.ca> 2020-08-31 01:01:43-06:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-08-31 20:29:57+03:00
log82273f1a2a3bf3d90e24c3aeb77fbcdafdc82872
treed681f70c0060997151b50c7c9d21d0e3b041b504
parent400d8d0b82b5f0aa7afe0ac8e4776daa8ebbac31

translate_c: fix shadowing on nested blocks


2 files changed, 18 insertions(+), 1 deletions(-)

src-self-hosted/translate_c.zig+1-1
...@@ -168,7 +168,7 @@ const Scope = struct {...@@ -168,7 +168,7 @@ const Scope = struct {
168168
169 fn localContains(scope: *Block, name: []const u8) bool {169 fn localContains(scope: *Block, name: []const u8) bool {
170 for (scope.variables.items) |p| {170 for (scope.variables.items) |p| {
171 if (mem.eql(u8, p.name, name))171 if (mem.eql(u8, p.alias, name))
172 return true;172 return true;
173 }173 }
174 return false;174 return false;
test/run_translated_c.zig+17
...@@ -3,6 +3,23 @@ const tests = @import("tests.zig");...@@ -3,6 +3,23 @@ const tests = @import("tests.zig");
3const nl = std.cstr.line_sep;3const nl = std.cstr.line_sep;
44
5pub fn addCases(cases: *tests.RunTranslatedCContext) void {5pub fn addCases(cases: *tests.RunTranslatedCContext) void {
6 cases.add("variable shadowing type type",
7 \\#include <stdlib.h>
8 \\int main() {
9 \\ int type = 1;
10 \\ if (type != 1) abort();
11 \\}
12 , "");
13
14 cases.add("assignment as expression",
15 \\#include <stdlib.h>
16 \\int main() {
17 \\ int a, b, c, d = 5;
18 \\ int e = a = b = c = d;
19 \\ if (e != 5) abort();
20 \\}
21 , "");
22
6 cases.add("static variable in block scope",23 cases.add("static variable in block scope",
7 \\#include <stdlib.h>24 \\#include <stdlib.h>
8 \\int foo() {25 \\int foo() {