translate_c: fix shadowing on nested blocks
This commit is contained in:
parent
400d8d0b82
commit
82273f1a2a
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user