mirror of
https://github.com/ziglang/zig.git
synced 2026-02-15 13:58:27 +00:00
Sema: implement zirRetErrValueCode
This commit is contained in:
parent
d557dedf6c
commit
7c0614ea65
17
src/Sema.zig
17
src/Sema.zig
@ -771,7 +771,7 @@ fn analyzeBodyInner(
|
||||
.ptr_type => try sema.zirPtrType(block, inst),
|
||||
.ptr_type_simple => try sema.zirPtrTypeSimple(block, inst),
|
||||
.ref => try sema.zirRef(block, inst),
|
||||
.ret_err_value_code => try sema.zirRetErrValueCode(block, inst),
|
||||
.ret_err_value_code => try sema.zirRetErrValueCode(inst),
|
||||
.shr => try sema.zirShr(block, inst, .shr),
|
||||
.shr_exact => try sema.zirShr(block, inst, .shr_exact),
|
||||
.slice_end => try sema.zirSliceEnd(block, inst),
|
||||
@ -9250,10 +9250,17 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
|
||||
return sema.analyzeDeclRef(embed_file.owner_decl);
|
||||
}
|
||||
|
||||
fn zirRetErrValueCode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
|
||||
_ = block;
|
||||
_ = inst;
|
||||
return sema.fail(block, sema.src, "TODO implement zirRetErrValueCode", .{});
|
||||
fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
|
||||
const inst_data = sema.code.instructions.items(.data)[inst].str_tok;
|
||||
const err_name = inst_data.get(sema.code);
|
||||
|
||||
// Return the error code from the function.
|
||||
const kv = try sema.mod.getErrorValue(err_name);
|
||||
const result_inst = try sema.addConstant(
|
||||
try Type.Tag.error_set_single.create(sema.arena, kv.key),
|
||||
try Value.Tag.@"error".create(sema.arena, .{ .name = kv.key }),
|
||||
);
|
||||
return result_inst;
|
||||
}
|
||||
|
||||
fn zirShl(
|
||||
|
||||
@ -108,7 +108,10 @@ test "mixing normal and error defers" {
|
||||
}
|
||||
|
||||
test "errdefer with payload" {
|
||||
if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
|
||||
const S = struct {
|
||||
fn foo() !i32 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user