diff --git a/src/Sema.zig b/src/Sema.zig index 32f611ce3ea9472f64b2d44e18b564175301b662..5f92e12b04d5c64f9e279356efa61b00c585d0af 100644 --- a/src/Sema.zig +++ b/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); diff --git a/test/behavior/type_info.zig b/test/behavior/type_info.zig index 2b7a66c763f2f213b9fd109b5ef0717d13fc4102..86e2eccc4c957accf1da4055f154b52b9133078a 100644 --- a/test/behavior/type_info.zig +++ b/test/behavior/type_info.zig @@ -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); +}