authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-11 20:44:10-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-03-11 20:44:10-07:00
log60d6037f236379e521ccb7a8e1b7d24ed469ac3f
tree86db209c223176e6feda699d92612844dc211bc7
parent55ba335e0ffc2af76bf0743d98f5a959ccce0409

Sema: fix inline/comptime function calls with inferred errors


2 files changed, 26 insertions(+), 13 deletions(-)

src/Module.zig+15
......@@ -1542,6 +1542,21 @@ pub const Fn = struct {
15421542 // const zir = func.owner_decl.getFileScope().zir;
15431543 return func.param_names[index];
15441544 }
1545
1546 pub fn hasInferredErrorSet(func: Fn) bool {
1547 const zir = func.owner_decl.getFileScope().zir;
1548 const zir_tags = zir.instructions.items(.tag);
1549 switch (zir_tags[func.zir_body_inst]) {
1550 .func => return false,
1551 .func_inferred => return true,
1552 .extended => {
1553 const extended = zir.instructions.items(.data)[func.zir_body_inst].extended;
1554 const small = @bitCast(Zir.Inst.ExtendedFunc.Small, extended.small);
1555 return small.is_inferred_error;
1556 },
1557 else => unreachable,
1558 }
1559 }
15451560};
15461561
15471562pub const Var = struct {
src/Sema.zig+11-13
......@@ -4666,20 +4666,18 @@ fn analyzeCall(
46664666 const bare_return_type = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst);
46674667 // Create a fresh inferred error set type for inline/comptime calls.
46684668 const fn_ret_ty = blk: {
4669 if (func_ty_info.return_type.castTag(.error_union)) |payload| {
4670 if (payload.data.error_set.tag() == .error_set_inferred) {
4671 const node = try sema.gpa.create(Module.Fn.InferredErrorSetListNode);
4672 node.data = .{ .func = module_fn };
4673 if (parent_func) |some| {
4674 some.inferred_error_sets.prepend(node);
4675 }
4676
4677 const error_set_ty = try Type.Tag.error_set_inferred.create(sema.arena, &node.data);
4678 break :blk try Type.Tag.error_union.create(sema.arena, .{
4679 .error_set = error_set_ty,
4680 .payload = bare_return_type,
4681 });
4669 if (module_fn.hasInferredErrorSet()) {
4670 const node = try sema.gpa.create(Module.Fn.InferredErrorSetListNode);
4671 node.data = .{ .func = module_fn };
4672 if (parent_func) |some| {
4673 some.inferred_error_sets.prepend(node);
46824674 }
4675
4676 const error_set_ty = try Type.Tag.error_set_inferred.create(sema.arena, &node.data);
4677 break :blk try Type.Tag.error_union.create(sema.arena, .{
4678 .error_set = error_set_ty,
4679 .payload = bare_return_type,
4680 });
46834681 }
46844682 break :blk bare_return_type;
46854683 };