| author | |
| committer | |
| log | f7822029100de9f91c9a7758ffb32d95f7768f70 |
| tree | 551ee2c7a6600facd02e27c62650483f89ba0986 |
| parent | abb8e7478d365088301a9390c12f86b2ad381ce9 |
Closes #173542 files changed, 16 insertions(+), 1 deletions(-)
src/Sema.zig+4-1| ... | ... | @@ -22368,7 +22368,10 @@ fn zirErrorCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData |
| 22368 | 22368 | |
| 22369 | 22369 | try sema.requireRuntimeBlock(block, src, operand_src); |
| 22370 | 22370 | const err_int_ty = try mod.errorIntType(); |
| 22371 | if (block.wantSafety() and !dest_ty.isAnyError(mod) and sema.mod.backendSupportsFeature(.error_set_has_value)) { | |
| 22371 | if (block.wantSafety() and !dest_ty.isAnyError(mod) and | |
| 22372 | dest_ty.toIntern() != .adhoc_inferred_error_set_type and | |
| 22373 | sema.mod.backendSupportsFeature(.error_set_has_value)) | |
| 22374 | { | |
| 22372 | 22375 | if (dest_tag == .ErrorUnion) { |
| 22373 | 22376 | const err_code = try sema.analyzeErrUnionCode(block, operand_src, operand); |
| 22374 | 22377 | const err_int = try block.addBitCast(err_int_ty, err_code); |
test/behavior/error.zig+12| ... | ... | @@ -1027,3 +1027,15 @@ test "generic type constructed from inferred error set of unresolved function" { |
| 1027 | 1027 | }; |
| 1028 | 1028 | _ = std.io.multiWriter(.{S.writer()}); |
| 1029 | 1029 | } |
| 1030 | ||
| 1031 | test "errorCast to adhoc inferred error set" { | |
| 1032 | const S = struct { | |
| 1033 | inline fn baz() !i32 { | |
| 1034 | return @errorCast(err()); | |
| 1035 | } | |
| 1036 | fn err() anyerror!i32 { | |
| 1037 | return 1234; | |
| 1038 | } | |
| 1039 | }; | |
| 1040 | try std.testing.expect((try S.baz()) == 1234); | |
| 1041 | } |