diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-10-12 21:54:59 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-10-12 22:03:39 -0700 |
| commit | e6b73be870a39f4da7a08a40da23e38b5e9613da (patch) | |
| tree | b21b81ecc4867273bf864988a8d63bb27b12b6c2 /src/Sema.zig | |
| parent | 2769215b9037bb1f407e07887d4d21957ce1a9e0 (diff) | |
| download | zig-e6b73be870a39f4da7a08a40da23e38b5e9613da.tar.gz zig-e6b73be870a39f4da7a08a40da23e38b5e9613da.zip | |
Sema: fix crash when coercion dest is var args
When analyzing the `as` ZIR instruction, an assertion would trip if the
result type was a var args function argument. The fix is simple: inline
a little bit of the `resolveType` logic into `analyzeAs` to make it
detect this situation - which it was already attempting to do.
Closes #16197
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index c9dacd1185..559f5d2731 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -9846,11 +9846,19 @@ fn analyzeAs( const mod = sema.mod; const operand = try sema.resolveInst(zir_operand); if (zir_dest_type == .var_args_param_type) return operand; - const dest_ty = sema.resolveType(block, src, zir_dest_type) catch |err| switch (err) { + const operand_air_inst = sema.resolveInst(zir_dest_type) catch |err| switch (err) { error.GenericPoison => return operand, else => |e| return e, }; - if (dest_ty.zigTypeTag(mod) == .NoReturn) { + if (operand_air_inst == .var_args_param_type) return operand; + const dest_ty = sema.analyzeAsType(block, src, operand_air_inst) catch |err| switch (err) { + error.GenericPoison => return operand, + else => |e| return e, + }; + const dest_ty_tag = dest_ty.zigTypeTagOrPoison(mod) catch |err| switch (err) { + error.GenericPoison => return operand, + }; + if (dest_ty_tag == .NoReturn) { return sema.fail(block, src, "cannot cast to noreturn", .{}); } const is_ret = if (Zir.refToIndex(zir_dest_type)) |ptr_index| |
