mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
Sema: fix @typeInfo of function with generic return type and IES
Resolves: #20088
This commit is contained in:
parent
5317d88414
commit
3031d81387
14
src/Sema.zig
14
src/Sema.zig
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user