diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-06-01 00:37:28 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-06-01 01:24:11 +0300 |
| commit | f2626a3d8ecddf48a08982ca78bff03e9d39d321 (patch) | |
| tree | 63f38df1e2d3e9ee24f07b7280841d08e9a10806 | |
| parent | e49fd39463be413a66920087d77eac983a91cb71 (diff) | |
| download | zig-f2626a3d8ecddf48a08982ca78bff03e9d39d321.tar.gz zig-f2626a3d8ecddf48a08982ca78bff03e9d39d321.zip | |
Sema: `validate{Array,Struct}Init` shortcut only valid if base ptr is comptime known
| -rw-r--r-- | src/Sema.zig | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 42b43d656f..42e37c7312 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -3340,7 +3340,9 @@ fn validateStructInit( const struct_ptr = try sema.resolveInst(struct_ptr_zir_ref); const struct_ty = sema.typeOf(struct_ptr).childType(); - if (is_comptime or block.is_comptime) { + if ((is_comptime or block.is_comptime) and + (try sema.resolveDefinedValue(block, init_src, struct_ptr)) != null) + { // In this case the only thing we need to do is evaluate the implicit // store instructions for default field values, and report any missing fields. // Avoid the cost of the extra machinery for detecting a comptime struct init value. @@ -3544,7 +3546,9 @@ fn zirValidateArrayInit( }); } - if (is_comptime or block.is_comptime) { + if ((is_comptime or block.is_comptime) and + (try sema.resolveDefinedValue(block, init_src, array_ptr)) != null) + { // In this case the comptime machinery will have evaluated the store instructions // at comptime so we have almost nothing to do here. However, in case of a // sentinel-terminated array, the sentinel will not have been populated by |
