Commit 36df79cd37

Veikka Tuominen <git@vexu.eu>
2022-05-31 15:43:58
stage2: ignore generic return type when hashing function type
Generic parameter types are already ignored.
1 parent febc7d3
Changed files (2)
src
test
behavior
src/type.zig
@@ -1036,7 +1036,9 @@ pub const Type = extern union {
                 std.hash.autoHash(hasher, std.builtin.TypeId.Fn);
 
                 const fn_info = ty.fnInfo();
-                hashWithHasher(fn_info.return_type, hasher, mod);
+                if (fn_info.return_type.tag() != .generic_poison) {
+                    hashWithHasher(fn_info.return_type, hasher, mod);
+                }
                 std.hash.autoHash(hasher, fn_info.alignment);
                 std.hash.autoHash(hasher, fn_info.cc);
                 std.hash.autoHash(hasher, fn_info.is_var_args);
test/behavior/basic.zig
@@ -987,3 +987,21 @@ test "array type comes from generic function" {
     const args = [_]S.A(){.{}};
     _ = args;
 }
+
+test "generic function uses return type of other generic function" {
+    if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+
+    const S = struct {
+        fn call(
+            f: anytype,
+            args: anytype,
+        ) @TypeOf(@call(.{}, f, @as(@TypeOf(args), undefined))) {
+            return @call(.{}, f, args);
+        }
+
+        fn func(arg: anytype) @TypeOf(arg) {
+            return arg;
+        }
+    };
+    try std.testing.expect(S.call(S.func, .{@as(u8, 1)}) == 1);
+}