diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-03-10 17:09:23 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-03-10 17:52:18 -0700 |
| commit | 273da9efd9238e20da1299789537b00de2f0ebd8 (patch) | |
| tree | 54905594f55be9fd19a179ab1bcaeb1900d02bc1 /test/behavior/tuple.zig | |
| parent | a30d283981ae31ed0212ef153f086e07daeffe65 (diff) | |
| download | zig-273da9efd9238e20da1299789537b00de2f0ebd8.tar.gz zig-273da9efd9238e20da1299789537b00de2f0ebd8.zip | |
AstGen: structInitExpr and arrayInitExpr avoid crash
when an inferred alloc is passed as the result pointer of a block.
Diffstat (limited to 'test/behavior/tuple.zig')
| -rw-r--r-- | test/behavior/tuple.zig | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/test/behavior/tuple.zig b/test/behavior/tuple.zig index db2816831d..1c87bdd5b7 100644 --- a/test/behavior/tuple.zig +++ b/test/behavior/tuple.zig @@ -165,3 +165,35 @@ test "array-like initializer for tuple types" { try S.doTheTest(); comptime try S.doTheTest(); } + +test "anon struct as the result from a labeled block" { + const S = struct { + fn doTheTest() !void { + const precomputed = comptime blk: { + var x: i32 = 1234; + break :blk .{ + .x = x, + }; + }; + try expect(precomputed.x == 1234); + } + }; + + try S.doTheTest(); + comptime try S.doTheTest(); +} + +test "tuple as the result from a labeled block" { + const S = struct { + fn doTheTest() !void { + const precomputed = comptime blk: { + var x: i32 = 1234; + break :blk .{x}; + }; + try expect(precomputed[0] == 1234); + } + }; + + try S.doTheTest(); + comptime try S.doTheTest(); +} |
