authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-13 15:23:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-18 19:02:06-07:00
log722bd22508a7f1f5ab05685002d30e8d7fc2b2a2
treefab71e5564eb42147bd1863fa67ebd1404cd6c6e
parent684aee32209932166713462cc341fa469aad0728

Sema: fix not setting up adhoc inferred error set correctly

for comptime/inline calls.

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

src/Sema.zig+10-12
......@@ -157,9 +157,9 @@ pub const InferredErrorSet = struct {
157157 arena: Allocator,
158158 ) !void {
159159 switch (err_set_ty.toIntern()) {
160 .anyerror_type => {
161 self.resolved = .anyerror_type;
162 },
160 .anyerror_type => self.resolved = .anyerror_type,
161 .adhoc_inferred_error_set_type => {}, // Adding an inferred error set to itself.
162
163163 else => switch (ip.indexToKey(err_set_ty.toIntern())) {
164164 .error_set_type => |error_set_type| {
165165 for (error_set_type.names.get(ip)) |name| {
......@@ -7055,12 +7055,11 @@ fn analyzeCall(
70557055
70567056 if (module_fn.analysis(ip).inferred_error_set) {
70577057 // Create a fresh inferred error set type for inline/comptime calls.
7058 const error_set_ty = try mod.intern(.{ .inferred_error_set_type = module_fn_index });
70597058 const ies = try sema.arena.create(InferredErrorSet);
7060 ies.* = .{ .func = module_fn_index };
7059 ies.* = .{ .func = .none };
70617060 sema.fn_ret_ty_ies = ies;
70627061 sema.fn_ret_ty = (try ip.get(gpa, .{ .error_union_type = .{
7063 .error_set_type = error_set_ty,
7062 .error_set_type = .adhoc_inferred_error_set_type,
70647063 .payload_type = bare_return_type.toIntern(),
70657064 } })).toType();
70667065 }
......@@ -7081,6 +7080,7 @@ fn analyzeCall(
70817080 }
70827081 }
70837082
7083 new_fn_info.return_type = sema.fn_ret_ty.toIntern();
70847084 const new_func_resolved_ty = try mod.funcType(new_fn_info);
70857085 if (!is_comptime_call and !block.is_typeof) {
70867086 try sema.emitDbgInline(block, parent_func_index, module_fn_index, new_func_resolved_ty, .dbg_inline_begin);
......@@ -8841,7 +8841,8 @@ fn funcCommon(
88418841 if (inferred_error_set) {
88428842 assert(!is_extern);
88438843 assert(has_body);
8844 try sema.validateErrorUnionPayloadType(block, bare_return_type, ret_ty_src);
8844 if (!ret_poison)
8845 try sema.validateErrorUnionPayloadType(block, bare_return_type, ret_ty_src);
88458846 const func_index = try ip.getFuncDeclIes(gpa, .{
88468847 .owner_decl = sema.owner_decl_index,
88478848
......@@ -34051,11 +34052,8 @@ fn resolveInferredErrorSet(
3405134052 // In order to ensure that all dependencies are properly added to the set,
3405234053 // we need to ensure the function body is analyzed of the inferred error
3405334054 // set. However, in the case of comptime/inline function calls with
34054 // inferred error sets, each call gets a new InferredErrorSet object, which
34055 // contains the `InternPool.Index` of the callee. Not only is the function
34056 // not relevant to the inferred error set in this case, it may be a generic
34057 // function which would cause an assertion failure if we called
34058 // `ensureFuncBodyAnalyzed` on it here.
34055 // inferred error sets, each call gets an adhoc InferredErrorSet object, which
34056 // has no corresponding function body.
3405934057 const ies_func_owner_decl = mod.declPtr(func.owner_decl);
3406034058 const ies_func_info = mod.typeToFunc(ies_func_owner_decl.ty).?;
3406134059 // if ies declared by a inline function with generic return type, the return_type should be generic_poison,