authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-12-18 00:30:16+01:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2021-12-21 01:41:50+01:00
log138f85bf258d3520591e4a5abfb6d5db7ae45d97
tree186349f134a5defe0896738ed908d5cbb5e52672
parent16bddecff99eafb6c60d2c7a406d92d9c2d3c35a

stage2: only create inferred error sets for inferred error set functions


1 files changed, 14 insertions(+), 12 deletions(-)

src/Sema.zig+14-12
......@@ -3912,18 +3912,20 @@ fn analyzeCall(
39123912 const ret_ty_inst = try sema.resolveBody(&child_block, fn_info.ret_ty_body);
39133913 const ret_ty_src = func_src; // TODO better source location
39143914 const bare_return_type = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst);
3915 // If the function has an inferred error set, `bare_return_type` is the payload type only.
3915 // Create a fresh inferred error set type for inline/comptime calls.
39163916 const fn_ret_ty = blk: {
3917 if (func_ty_info.return_type.tag() == .error_union) {
3918 const node = try sema.gpa.create(Module.Fn.InferredErrorSetListNode);
3919 node.data = .{ .func = module_fn };
3920 parent_func.?.inferred_error_sets.prepend(node);
3921
3922 const error_set_ty = try Type.Tag.error_set_inferred.create(sema.arena, &node.data);
3923 break :blk try Type.Tag.error_union.create(sema.arena, .{
3924 .error_set = error_set_ty,
3925 .payload = bare_return_type,
3926 });
3917 if (func_ty_info.return_type.castTag(.error_union)) |payload| {
3918 if (payload.data.error_set.tag() == .error_set_inferred) {
3919 const node = try sema.gpa.create(Module.Fn.InferredErrorSetListNode);
3920 node.data = .{ .func = module_fn };
3921 parent_func.?.inferred_error_sets.prepend(node);
3922
3923 const error_set_ty = try Type.Tag.error_set_inferred.create(sema.arena, &node.data);
3924 break :blk try Type.Tag.error_union.create(sema.arena, .{
3925 .error_set = error_set_ty,
3926 .payload = bare_return_type,
3927 });
3928 }
39273929 }
39283930 break :blk bare_return_type;
39293931 };
......@@ -12473,7 +12475,7 @@ fn coerceInMemoryAllowed(
1247312475 dest_ty: Type,
1247412476 src_ty: Type,
1247512477 dest_is_mut: bool,
12476 target: std.Target
12478 target: std.Target,
1247712479) CompileError!InMemoryCoercionResult {
1247812480 if (dest_ty.eql(src_ty))
1247912481 return .ok;