aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/tuple.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-03-10 17:09:23 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-03-10 17:52:18 -0700
commit273da9efd9238e20da1299789537b00de2f0ebd8 (patch)
tree54905594f55be9fd19a179ab1bcaeb1900d02bc1 /test/behavior/tuple.zig
parenta30d283981ae31ed0212ef153f086e07daeffe65 (diff)
downloadzig-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.zig32
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();
+}