aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2021-12-18 00:30:16 +0100
committerRobin Voetter <robin@voetter.nl>2021-12-21 01:41:50 +0100
commit138f85bf258d3520591e4a5abfb6d5db7ae45d97 (patch)
tree186349f134a5defe0896738ed908d5cbb5e52672
parent16bddecff99eafb6c60d2c7a406d92d9c2d3c35a (diff)
downloadzig-138f85bf258d3520591e4a5abfb6d5db7ae45d97.tar.gz
zig-138f85bf258d3520591e4a5abfb6d5db7ae45d97.zip
stage2: only create inferred error sets for inferred error set functions
-rw-r--r--src/Sema.zig26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index a51e6ffbf3..05cdcb794f 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -3912,18 +3912,20 @@ fn analyzeCall(
const ret_ty_inst = try sema.resolveBody(&child_block, fn_info.ret_ty_body);
const ret_ty_src = func_src; // TODO better source location
const bare_return_type = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst);
- // If the function has an inferred error set, `bare_return_type` is the payload type only.
+ // Create a fresh inferred error set type for inline/comptime calls.
const fn_ret_ty = blk: {
- if (func_ty_info.return_type.tag() == .error_union) {
- const node = try sema.gpa.create(Module.Fn.InferredErrorSetListNode);
- node.data = .{ .func = module_fn };
- parent_func.?.inferred_error_sets.prepend(node);
-
- const error_set_ty = try Type.Tag.error_set_inferred.create(sema.arena, &node.data);
- break :blk try Type.Tag.error_union.create(sema.arena, .{
- .error_set = error_set_ty,
- .payload = bare_return_type,
- });
+ if (func_ty_info.return_type.castTag(.error_union)) |payload| {
+ if (payload.data.error_set.tag() == .error_set_inferred) {
+ const node = try sema.gpa.create(Module.Fn.InferredErrorSetListNode);
+ node.data = .{ .func = module_fn };
+ parent_func.?.inferred_error_sets.prepend(node);
+
+ const error_set_ty = try Type.Tag.error_set_inferred.create(sema.arena, &node.data);
+ break :blk try Type.Tag.error_union.create(sema.arena, .{
+ .error_set = error_set_ty,
+ .payload = bare_return_type,
+ });
+ }
}
break :blk bare_return_type;
};
@@ -12473,7 +12475,7 @@ fn coerceInMemoryAllowed(
dest_ty: Type,
src_ty: Type,
dest_is_mut: bool,
- target: std.Target
+ target: std.Target,
) CompileError!InMemoryCoercionResult {
if (dest_ty.eql(src_ty))
return .ok;