aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/basic.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-06-01 02:19:40 +0300
committerVeikka Tuominen <git@vexu.eu>2022-06-01 13:01:39 +0300
commit9431100736abe63c361506411a40d143b23091d9 (patch)
treebdea60c2a28a88a9b49472ec7b31507d3fb22b87 /test/behavior/basic.zig
parent3c4e7abfbff9fbdb967308659951ca091b346bac (diff)
downloadzig-9431100736abe63c361506411a40d143b23091d9.tar.gz
zig-9431100736abe63c361506411a40d143b23091d9.zip
Sema: apply previous changes to `validateUnionInit`
Diffstat (limited to 'test/behavior/basic.zig')
-rw-r--r--test/behavior/basic.zig48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig
index 32df664bae..3129091091 100644
--- a/test/behavior/basic.zig
+++ b/test/behavior/basic.zig
@@ -1005,3 +1005,51 @@ test "generic function uses return type of other generic function" {
};
try std.testing.expect(S.call(S.func, .{@as(u8, 1)}) == 1);
}
+
+test "const alloc with comptime known initializer is made comptime known" {
+ const S = struct {
+ a: bool,
+ b: [2]u8,
+ };
+ {
+ const s: S = .{
+ .a = false,
+ .b = .{ 1, 2 },
+ };
+ if (s.a) @compileError("bad");
+ }
+ {
+ const s: S = .{
+ .a = false,
+ .b = [2]u8{ 1, 2 },
+ };
+ if (s.a) @compileError("bad");
+ }
+ {
+ const s: S = comptime .{
+ .a = false,
+ .b = .{ 1, 2 },
+ };
+ if (s.a) @compileError("bad");
+ }
+ {
+ const Const = struct {
+ limbs: []const usize,
+ positive: bool,
+ };
+ const biggest: Const = .{
+ .limbs = &([1]usize{comptime std.math.maxInt(usize)} ** 128),
+ .positive = false,
+ };
+ if (biggest.positive) @compileError("bad");
+ }
+ {
+ const U = union(enum) {
+ a: usize,
+ };
+ const u: U = .{
+ .a = comptime std.math.maxInt(usize),
+ };
+ if (u.a == 0) @compileError("bad");
+ }
+}