| author | |
| committer | |
| log | 9431100736abe63c361506411a40d143b23091d9 |
| tree | bdea60c2a28a88a9b49472ec7b31507d3fb22b87 |
| parent | 3c4e7abfbff9fbdb967308659951ca091b346bac |
3 files changed, 65 insertions(+), 5 deletions(-)
lib/std/math/big/int.zig+2-3| ... | ... | @@ -2063,9 +2063,8 @@ pub const Const = struct { |
| 2063 | 2063 | // This is the inverse of calcDivLimbsBufferLen |
| 2064 | 2064 | const available_len = (limbs.len / 3) - 2; |
| 2065 | 2065 | |
| 2066 | // TODO https://github.com/ziglang/zig/issues/11439 | |
| 2067 | const biggest = comptime Const{ | |
| 2068 | .limbs = &([1]Limb{math.maxInt(Limb)} ** available_len), | |
| 2066 | const biggest: Const = .{ | |
| 2067 | .limbs = &([1]Limb{comptime math.maxInt(Limb)} ** available_len), | |
| 2069 | 2068 | .positive = false, |
| 2070 | 2069 | }; |
| 2071 | 2070 | var buf: [biggest.sizeInBaseUpperBound(radix)]u8 = undefined; |
src/Sema.zig+15-2| ... | ... | @@ -3215,7 +3215,9 @@ fn validateUnionInit( |
| 3215 | 3215 | return sema.failWithOwnedErrorMsg(block, msg); |
| 3216 | 3216 | } |
| 3217 | 3217 | |
| 3218 | if (is_comptime or block.is_comptime) { | |
| 3218 | if ((is_comptime or block.is_comptime) and | |
| 3219 | (try sema.resolveDefinedValue(block, init_src, union_ptr)) != null) | |
| 3220 | { | |
| 3219 | 3221 | // In this case, comptime machinery already did everything. No work to do here. |
| 3220 | 3222 | return; |
| 3221 | 3223 | } |
| ... | ... | @@ -3261,7 +3263,18 @@ fn validateUnionInit( |
| 3261 | 3263 | if (store_inst == field_ptr_air_inst) break; |
| 3262 | 3264 | if (air_tags[store_inst] != .store) continue; |
| 3263 | 3265 | const bin_op = air_datas[store_inst].bin_op; |
| 3264 | if (bin_op.lhs != field_ptr_air_ref) continue; | |
| 3266 | var lhs = bin_op.lhs; | |
| 3267 | if (Air.refToIndex(lhs)) |lhs_index| { | |
| 3268 | if (air_tags[lhs_index] == .bitcast) { | |
| 3269 | lhs = air_datas[lhs_index].ty_op.operand; | |
| 3270 | block_index -= 1; | |
| 3271 | } | |
| 3272 | } | |
| 3273 | if (lhs != field_ptr_air_ref) continue; | |
| 3274 | while (block_index > 0) : (block_index -= 1) { | |
| 3275 | const block_inst = block.instructions.items[block_index - 1]; | |
| 3276 | if (air_tags[block_inst] != .dbg_stmt) break; | |
| 3277 | } | |
| 3265 | 3278 | if (block_index > 0 and |
| 3266 | 3279 | field_ptr_air_inst == block.instructions.items[block_index - 1]) |
| 3267 | 3280 | { |
test/behavior/basic.zig+48| ... | ... | @@ -1005,3 +1005,51 @@ test "generic function uses return type of other generic function" { |
| 1005 | 1005 | }; |
| 1006 | 1006 | try std.testing.expect(S.call(S.func, .{@as(u8, 1)}) == 1); |
| 1007 | 1007 | } |
| 1008 | ||
| 1009 | test "const alloc with comptime known initializer is made comptime known" { | |
| 1010 | const S = struct { | |
| 1011 | a: bool, | |
| 1012 | b: [2]u8, | |
| 1013 | }; | |
| 1014 | { | |
| 1015 | const s: S = .{ | |
| 1016 | .a = false, | |
| 1017 | .b = .{ 1, 2 }, | |
| 1018 | }; | |
| 1019 | if (s.a) @compileError("bad"); | |
| 1020 | } | |
| 1021 | { | |
| 1022 | const s: S = .{ | |
| 1023 | .a = false, | |
| 1024 | .b = [2]u8{ 1, 2 }, | |
| 1025 | }; | |
| 1026 | if (s.a) @compileError("bad"); | |
| 1027 | } | |
| 1028 | { | |
| 1029 | const s: S = comptime .{ | |
| 1030 | .a = false, | |
| 1031 | .b = .{ 1, 2 }, | |
| 1032 | }; | |
| 1033 | if (s.a) @compileError("bad"); | |
| 1034 | } | |
| 1035 | { | |
| 1036 | const Const = struct { | |
| 1037 | limbs: []const usize, | |
| 1038 | positive: bool, | |
| 1039 | }; | |
| 1040 | const biggest: Const = .{ | |
| 1041 | .limbs = &([1]usize{comptime std.math.maxInt(usize)} ** 128), | |
| 1042 | .positive = false, | |
| 1043 | }; | |
| 1044 | if (biggest.positive) @compileError("bad"); | |
| 1045 | } | |
| 1046 | { | |
| 1047 | const U = union(enum) { | |
| 1048 | a: usize, | |
| 1049 | }; | |
| 1050 | const u: U = .{ | |
| 1051 | .a = comptime std.math.maxInt(usize), | |
| 1052 | }; | |
| 1053 | if (u.a == 0) @compileError("bad"); | |
| 1054 | } | |
| 1055 | } |