authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-02-05 21:26:04+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-02-05 21:26:04+00:00
log3031d813874f6d6ad9ae4b793e3af6cdf632fa66
treefa1880e43789f3f25db416be67821f3e00d058fc
parent5317d88414324c6555338e8574811c6710df4e44
signaturelock-open Commit is signed but in an unrecognized format.

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

Resolves: #20088

2 files changed, 19 insertions(+), 4 deletions(-)

src/Sema.zig+10-4
...@@ -18145,10 +18145,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18145,10 +18145,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1814518145
18146 const ret_ty_opt = try pt.intern(.{ .opt = .{18146 const ret_ty_opt = try pt.intern(.{ .opt = .{
18147 .ty = try pt.intern(.{ .opt_type = .type_type }),18147 .ty = try pt.intern(.{ .opt_type = .type_type }),
18148 .val = if (func_ty_info.return_type == .generic_poison_type)18148 .val = opt_val: {
18149 .none18149 const ret_ty: Type = .fromInterned(func_ty_info.return_type);
18150 else18150 if (ret_ty.toIntern() == .generic_poison_type) break :opt_val .none;
18151 func_ty_info.return_type,18151 if (ret_ty.zigTypeTag(zcu) == .error_union) {
18152 if (ret_ty.errorUnionPayload(zcu).toIntern() == .generic_poison_type) {
18153 break :opt_val .none;
18154 }
18155 }
18156 break :opt_val ret_ty.toIntern();
18157 },
18152 } });18158 } });
1815318159
18154 const callconv_ty = try sema.getBuiltinType(src, .CallingConvention);18160 const callconv_ty = try sema.getBuiltinType(src, .CallingConvention);
test/behavior/type_info.zig+9
...@@ -675,3 +675,12 @@ test "@typeInfo only contains pub decls" {...@@ -675,3 +675,12 @@ test "@typeInfo only contains pub decls" {
675 try std.testing.expectEqualStrings("Enum", decls[0].name);675 try std.testing.expectEqualStrings("Enum", decls[0].name);
676 try std.testing.expectEqualStrings("Struct", decls[1].name);676 try std.testing.expectEqualStrings("Struct", decls[1].name);
677}677}
678
679test "@typeInfo function with generic return type and inferred error set" {
680 const S = struct {
681 fn testFn(comptime T: type) !T {}
682 };
683
684 const ret_ty = @typeInfo(@TypeOf(S.testFn)).@"fn".return_type;
685 comptime assert(ret_ty == null);
686}