Skip to content

Commit c1cc7b9

Browse files
Vexuandrewrk
authored andcommitted
stage2: ignore generic return type when hashing function type
Generic parameter types are already ignored.
1 parent f4a4694 commit c1cc7b9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/type.zig

+3-1
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,9 @@ pub const Type = extern union {
10361036
std.hash.autoHash(hasher, std.builtin.TypeId.Fn);
10371037

10381038
const fn_info = ty.fnInfo();
1039-
hashWithHasher(fn_info.return_type, hasher, mod);
1039+
if (fn_info.return_type.tag() != .generic_poison) {
1040+
hashWithHasher(fn_info.return_type, hasher, mod);
1041+
}
10401042
std.hash.autoHash(hasher, fn_info.alignment);
10411043
std.hash.autoHash(hasher, fn_info.cc);
10421044
std.hash.autoHash(hasher, fn_info.is_var_args);

test/behavior/basic.zig

+18
Original file line numberDiff line numberDiff line change
@@ -987,3 +987,21 @@ test "array type comes from generic function" {
987987
const args = [_]S.A(){.{}};
988988
_ = args;
989989
}
990+
991+
test "generic function uses return type of other generic function" {
992+
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
993+
994+
const S = struct {
995+
fn call(
996+
f: anytype,
997+
args: anytype,
998+
) @TypeOf(@call(.{}, f, @as(@TypeOf(args), undefined))) {
999+
return @call(.{}, f, args);
1000+
}
1001+
1002+
fn func(arg: anytype) @TypeOf(arg) {
1003+
return arg;
1004+
}
1005+
};
1006+
try std.testing.expect(S.call(S.func, .{@as(u8, 1)}) == 1);
1007+
}

0 commit comments

Comments
 (0)