aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-03-31 16:23:01 -0400
committerVeikka Tuominen <git@vexu.eu>2023-04-02 18:05:44 +0300
commitf4b411314ccf8e852d3febddc8b31ce1f533938b (patch)
tree41ff16cd4d9bec89e5f57be34e790017be93a4d0 /test/behavior
parent878163e58813aef968900aa7495dacc5220eb941 (diff)
downloadzig-f4b411314ccf8e852d3febddc8b31ce1f533938b.tar.gz
zig-f4b411314ccf8e852d3febddc8b31ce1f533938b.zip
Sema: defer stores to inferred allocs
This lets us generate the store with knowledge of the type to be stored. Therefore, we can avoid generating garbage Air with stores through pointers to comptime-only types which backends cannot lower. Closes #13410 Closes #15122
Diffstat (limited to 'test/behavior')
-rw-r--r--test/behavior/if.zig6
-rw-r--r--test/behavior/union.zig16
2 files changed, 16 insertions, 6 deletions
diff --git a/test/behavior/if.zig b/test/behavior/if.zig
index 730c0713c6..2294a2bcfd 100644
--- a/test/behavior/if.zig
+++ b/test/behavior/if.zig
@@ -140,12 +140,6 @@ test "if-else expression with runtime condition result location is inferred opti
}
test "result location with inferred type ends up being pointer to comptime_int" {
- if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
-
var a: ?u32 = 1234;
var b: u32 = 2000;
var c = if (a) |d| blk: {
diff --git a/test/behavior/union.zig b/test/behavior/union.zig
index 20ad0a60ff..e8a9f4c831 100644
--- a/test/behavior/union.zig
+++ b/test/behavior/union.zig
@@ -1540,3 +1540,19 @@ test "access the tag of a global tagged union" {
};
try expect(U.u == .a);
}
+
+test "coerce enum literal to union in result loc" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+
+ const U = union(enum) {
+ a,
+ b: u8,
+
+ fn doTest(c: bool) !void {
+ var u = if (c) .a else @This(){ .b = 0 };
+ try expect(u == .a);
+ }
+ };
+ try U.doTest(true);
+ comptime try U.doTest(true);
+}