Commit 82273f1a2a

Tadeo Kondrak <me@tadeo.ca>
2020-08-31 09:01:43
translate_c: fix shadowing on nested blocks
1 parent 400d8d0
Changed files (2)
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;
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() {