Sema: fix @typeInfo of function with generic return type and IES

Resolves: #20088
This commit is contained in:
mlugg 2025-02-05 21:26:04 +00:00
parent 5317d88414
commit 3031d81387
No known key found for this signature in database
GPG Key ID: 3F5B7DCCBF4AF02E
2 changed files with 19 additions and 4 deletions

View File

@ -18145,10 +18145,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
const ret_ty_opt = try pt.intern(.{ .opt = .{
.ty = try pt.intern(.{ .opt_type = .type_type }),
.val = if (func_ty_info.return_type == .generic_poison_type)
.none
else
func_ty_info.return_type,
.val = opt_val: {
const ret_ty: Type = .fromInterned(func_ty_info.return_type);
if (ret_ty.toIntern() == .generic_poison_type) break :opt_val .none;
if (ret_ty.zigTypeTag(zcu) == .error_union) {
if (ret_ty.errorUnionPayload(zcu).toIntern() == .generic_poison_type) {
break :opt_val .none;
}
}
break :opt_val ret_ty.toIntern();
},
} });
const callconv_ty = try sema.getBuiltinType(src, .CallingConvention);

View File

@ -675,3 +675,12 @@ test "@typeInfo only contains pub decls" {
try std.testing.expectEqualStrings("Enum", decls[0].name);
try std.testing.expectEqualStrings("Struct", decls[1].name);
}
test "@typeInfo function with generic return type and inferred error set" {
const S = struct {
fn testFn(comptime T: type) !T {}
};
const ret_ty = @typeInfo(@TypeOf(S.testFn)).@"fn".return_type;
comptime assert(ret_ty == null);
}