From 9431100736abe63c361506411a40d143b23091d9 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Wed, 1 Jun 2022 02:19:40 +0300 Subject: Sema: apply previous changes to `validateUnionInit` --- test/behavior/basic.zig | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'test/behavior/basic.zig') 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"); + } +} -- cgit v1.2.3