aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/basic.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/behavior/basic.zig')
-rw-r--r--test/behavior/basic.zig33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig
index 3129091091..a69df862c1 100644
--- a/test/behavior/basic.zig
+++ b/test/behavior/basic.zig
@@ -1,5 +1,6 @@
const std = @import("std");
const builtin = @import("builtin");
+const assert = std.debug.assert;
const mem = std.mem;
const expect = std.testing.expect;
const expectEqualStrings = std.testing.expectEqualStrings;
@@ -1053,3 +1054,35 @@ test "const alloc with comptime known initializer is made comptime known" {
if (u.a == 0) @compileError("bad");
}
}
+
+comptime {
+ // coerce result ptr outside a function
+ const S = struct { a: comptime_int };
+ var s: S = undefined;
+ s = S{ .a = 1 };
+ assert(s.a == 1);
+}
+
+test "switch inside @as gets correct type" {
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+
+ var a: u32 = 0;
+ var b: [2]u32 = undefined;
+ b[0] = @as(u32, switch (a) {
+ 1 => 1,
+ else => 0,
+ });
+}
+
+test "inline call of function with a switch inside the return statement" {
+ const S = struct {
+ inline fn foo(x: anytype) @TypeOf(x) {
+ return switch (x) {
+ 1 => 1,
+ else => unreachable,
+ };
+ }
+ };
+ try expect(S.foo(1) == 1);
+}