translate_c: fix shadowing on nested blocks

master
Tadeo Kondrak 2020-08-31 01:01:43 -06:00 committed by Veikka Tuominen
parent 400d8d0b82
commit 82273f1a2a
2 changed files with 18 additions and 1 deletions

View File

@ -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;

View File

@ -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() {