mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
parent
3e99afdbfe
commit
6d7fb8f19c
@ -1612,6 +1612,12 @@ fn analyzeBodyInner(
|
|||||||
const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
|
const extra = sema.code.extraData(Zir.Inst.Try, inst_data.payload_index);
|
||||||
const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len];
|
const inline_body = sema.code.extra[extra.end..][0..extra.data.body_len];
|
||||||
const err_union = try sema.resolveInst(extra.data.operand);
|
const err_union = try sema.resolveInst(extra.data.operand);
|
||||||
|
const err_union_ty = sema.typeOf(err_union);
|
||||||
|
if (err_union_ty.zigTypeTag() != .ErrorUnion) {
|
||||||
|
return sema.fail(block, operand_src, "expected error union type, found '{}'", .{
|
||||||
|
err_union_ty.fmt(sema.mod),
|
||||||
|
});
|
||||||
|
}
|
||||||
const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union);
|
const is_non_err = try sema.analyzeIsNonErrComptimeOnly(block, operand_src, err_union);
|
||||||
assert(is_non_err != .none);
|
assert(is_non_err != .none);
|
||||||
const is_non_err_tv = sema.resolveInstConst(block, operand_src, is_non_err, "try operand inside comptime block must be comptime-known") catch |err| {
|
const is_non_err_tv = sema.resolveInstConst(block, operand_src, is_non_err, "try operand inside comptime block must be comptime-known") catch |err| {
|
||||||
@ -1619,7 +1625,6 @@ fn analyzeBodyInner(
|
|||||||
return err;
|
return err;
|
||||||
};
|
};
|
||||||
if (is_non_err_tv.val.toBool()) {
|
if (is_non_err_tv.val.toBool()) {
|
||||||
const err_union_ty = sema.typeOf(err_union);
|
|
||||||
break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, err_union, operand_src, false);
|
break :blk try sema.analyzeErrUnionPayload(block, src, err_union_ty, err_union, operand_src, false);
|
||||||
}
|
}
|
||||||
const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse
|
const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse
|
||||||
|
|||||||
13
test/cases/compile_errors/comptime_try_non_error.zig
Normal file
13
test/cases/compile_errors/comptime_try_non_error.zig
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
export fn foo() void {
|
||||||
|
try bar();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bar() u8 {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// error
|
||||||
|
// backend=stage2
|
||||||
|
// target=native
|
||||||
|
//
|
||||||
|
// :2:12: error: expected error union type, found 'u8'
|
||||||
Loading…
x
Reference in New Issue
Block a user