authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-08 15:51:48-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-06-08 15:51:48-07:00
log7c0614ea659b3f404f9d702c990afcac5f0b1479
treea9630a72147c561d4d10636472c39ae1b1e33347
parentd557dedf6cb836e11038faada436299547044ffc

Sema: implement zirRetErrValueCode


2 files changed, 16 insertions(+), 6 deletions(-)

src/Sema.zig+12-5
...@@ -771,7 +771,7 @@ fn analyzeBodyInner(...@@ -771,7 +771,7 @@ fn analyzeBodyInner(
771 .ptr_type => try sema.zirPtrType(block, inst),771 .ptr_type => try sema.zirPtrType(block, inst),
772 .ptr_type_simple => try sema.zirPtrTypeSimple(block, inst),772 .ptr_type_simple => try sema.zirPtrTypeSimple(block, inst),
773 .ref => try sema.zirRef(block, inst),773 .ref => try sema.zirRef(block, inst),
774 .ret_err_value_code => try sema.zirRetErrValueCode(block, inst),774 .ret_err_value_code => try sema.zirRetErrValueCode(inst),
775 .shr => try sema.zirShr(block, inst, .shr),775 .shr => try sema.zirShr(block, inst, .shr),
776 .shr_exact => try sema.zirShr(block, inst, .shr_exact),776 .shr_exact => try sema.zirShr(block, inst, .shr_exact),
777 .slice_end => try sema.zirSliceEnd(block, inst),777 .slice_end => try sema.zirSliceEnd(block, inst),
...@@ -9250,10 +9250,17 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -9250,10 +9250,17 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
9250 return sema.analyzeDeclRef(embed_file.owner_decl);9250 return sema.analyzeDeclRef(embed_file.owner_decl);
9251}9251}
92529252
9253fn zirRetErrValueCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {9253fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
9254 _ = block;9254 const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
9255 _ = inst;9255 const err_name = inst_data.get(sema.code);
9256 return sema.fail(block, sema.src, "TODO implement zirRetErrValueCode", .{});9256
9257 // Return the error code from the function.
9258 const kv = try sema.mod.getErrorValue(err_name);
9259 const result_inst = try sema.addConstant(
9260 try Type.Tag.error_set_single.create(sema.arena, kv.key),
9261 try Value.Tag.@"error".create(sema.arena, .{ .name = kv.key }),
9262 );
9263 return result_inst;
9257}9264}
92589265
9259fn zirShl(9266fn zirShl(
test/behavior/defer.zig+4-1
...@@ -108,7 +108,10 @@ test "mixing normal and error defers" {...@@ -108,7 +108,10 @@ test "mixing normal and error defers" {
108}108}
109109
110test "errdefer with payload" {110test "errdefer with payload" {
111 if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO111 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
112 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
113 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
114 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
112115
113 const S = struct {116 const S = struct {
114 fn foo() !i32 {117 fn foo() !i32 {