diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/run_translated_c.zig | 13 | ||||
| -rw-r--r-- | test/translate_c.zig | 32 |
2 files changed, 35 insertions, 10 deletions
diff --git a/test/run_translated_c.zig b/test/run_translated_c.zig index e28bdc96f0..b8af201e36 100644 --- a/test/run_translated_c.zig +++ b/test/run_translated_c.zig @@ -909,4 +909,17 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void { \\ return 1 != 1; \\} , ""); + + cases.add("Comma operator should create new scope; issue #7989", + \\#include <stdlib.h> + \\#include <stdio.h> + \\int main(void) { + \\ if (1 || (abort(), 1)) {} + \\ if (0 && (1, printf("do not print\n"))) {} + \\ int x = 0; + \\ x = (x = 3, 4, x + 1); + \\ if (x != 4) abort(); + \\ return 0; + \\} + , ""); } diff --git a/test/translate_c.zig b/test/translate_c.zig index b8e00a690b..95969a2f72 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -1723,11 +1723,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} , &[_][]const u8{ \\pub export fn foo() c_int { - \\ _ = @as(c_int, 2); - \\ _ = @as(c_int, 4); - \\ _ = @as(c_int, 2); - \\ _ = @as(c_int, 4); - \\ return @as(c_int, 6); + \\ _ = (blk: { + \\ _ = @as(c_int, 2); + \\ break :blk @as(c_int, 4); + \\ }); + \\ return (blk: { + \\ _ = (blk_1: { + \\ _ = @as(c_int, 2); + \\ break :blk_1 @as(c_int, 4); + \\ }); + \\ break :blk @as(c_int, 6); + \\ }); \\} }); @@ -1774,8 +1780,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ while (true) { \\ var a_1: c_int = 4; \\ a_1 = 9; - \\ _ = @as(c_int, 6); - \\ return a_1; + \\ return (blk: { + \\ _ = @as(c_int, 6); + \\ break :blk a_1; + \\ }); \\ } \\ while (true) { \\ var a_1: c_int = 2; @@ -1805,9 +1813,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ var b: c_int = 4; \\ while ((i + @as(c_int, 2)) != 0) : (i = 2) { \\ var a: c_int = 2; - \\ a = 6; - \\ _ = @as(c_int, 5); - \\ _ = @as(c_int, 7); + \\ _ = (blk: { + \\ _ = (blk_1: { + \\ a = 6; + \\ break :blk_1 @as(c_int, 5); + \\ }); + \\ break :blk @as(c_int, 7); + \\ }); \\ } \\ } \\ var i: u8 = @bitCast(u8, @truncate(i8, @as(c_int, 2))); |
