From febc7d3cd63eefe91c7aaa95e3a274a0b44e353e Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Tue, 31 May 2022 16:21:36 +0300 Subject: Sema: take `dbg_stmt` into account in `zirResolveInferredAlloc` --- test/behavior/basic.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/behavior/basic.zig') diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index e887a1d4b6..8bc1ad5cf2 100644 --- a/test/behavior/basic.zig +++ b/test/behavior/basic.zig @@ -977,3 +977,13 @@ test "weird array and tuple initializations" { .b = if (a) .{ .e = .a } else .{ .e = .b }, }; } + +test "array type comes from generic function" { + const S = struct { + fn A() type { + return struct { a: u8 = 0 }; + } + }; + const args = [_]S.A(){.{}}; + _ = args; +} -- cgit v1.2.3 From 36df79cd3779b27a63f449618459603ce549660a Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Tue, 31 May 2022 16:43:58 +0300 Subject: stage2: ignore generic return type when hashing function type Generic parameter types are already ignored. --- src/type.zig | 4 +++- test/behavior/basic.zig | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'test/behavior/basic.zig') diff --git a/src/type.zig b/src/type.zig index ebb8bfd7c3..638145e8b1 100644 --- a/src/type.zig +++ b/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); diff --git a/test/behavior/basic.zig b/test/behavior/basic.zig index 8bc1ad5cf2..32df664bae 100644 --- a/test/behavior/basic.zig +++ b/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); +} -- cgit v1.2.3