aboutsummaryrefslogtreecommitdiff
path: root/test/stage2
diff options
context:
space:
mode:
authorg-w1 <jacoblevgw@gmail.com>2021-01-08 17:08:45 -0500
committerAndrew Kelley <andrew@ziglang.org>2021-01-18 19:29:18 -0700
commit3c2a9220edd59c2d7b50aca65e4cd0748cf2306f (patch)
treed5a15a892c9d0befc08bdeca0778718a2f1bcce4 /test/stage2
parent6c7e66613d57aec2f2949c065ea6431ff6c31f88 (diff)
downloadzig-3c2a9220edd59c2d7b50aca65e4cd0748cf2306f.tar.gz
zig-3c2a9220edd59c2d7b50aca65e4cd0748cf2306f.zip
stage2: fix orelse at comptime
There was just some untested code that did not work. .isnull -> .isnonnull and I had to add a .ref resultloc to make types match up.
Diffstat (limited to 'test/stage2')
-rw-r--r--test/stage2/test.zig47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/stage2/test.zig b/test/stage2/test.zig
index f2c0989b46..845b9b627d 100644
--- a/test/stage2/test.zig
+++ b/test/stage2/test.zig
@@ -1462,4 +1462,51 @@ pub fn addCases(ctx: *TestContext) !void {
"",
);
}
+ {
+ var case = ctx.exe("orelse at comptime", linux_x64);
+ case.addCompareOutput(
+ \\export fn _start() noreturn {
+ \\ const i: ?u64 = 0;
+ \\ const orelsed = i orelse 5;
+ \\ assert(orelsed == 0);
+ \\ exit();
+ \\}
+ \\fn assert(b: bool) void {
+ \\ if (!b) unreachable;
+ \\}
+ \\fn exit() noreturn {
+ \\ asm volatile ("syscall"
+ \\ :
+ \\ : [number] "{rax}" (231),
+ \\ [arg1] "{rdi}" (0)
+ \\ : "rcx", "r11", "memory"
+ \\ );
+ \\ unreachable;
+ \\}
+ ,
+ "",
+ );
+ case.addCompareOutput(
+ \\export fn _start() noreturn {
+ \\ const i: ?u64 = null;
+ \\ const orelsed = i orelse 5;
+ \\ assert(orelsed == 5);
+ \\ exit();
+ \\}
+ \\fn assert(b: bool) void {
+ \\ if (!b) unreachable;
+ \\}
+ \\fn exit() noreturn {
+ \\ asm volatile ("syscall"
+ \\ :
+ \\ : [number] "{rax}" (231),
+ \\ [arg1] "{rdi}" (0)
+ \\ : "rcx", "r11", "memory"
+ \\ );
+ \\ unreachable;
+ \\}
+ ,
+ "",
+ );
+ }
}