authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-08 19:03:47+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-11-11 17:59:53+02:00
logc4465556fdf14d87f718a7aced5210ec457c1f5a
tree4873404b890e9a97aa972b14561a268688b9b9db
parentcacfb0cfe4217a19872d62e248389bc522b36bf8

Type: check return_type for generic poison before comparing

Closes #13423

2 files changed, 15 insertions(+), 1 deletions(-)

src/type.zig+3-1
...@@ -640,7 +640,9 @@ pub const Type = extern union {...@@ -640,7 +640,9 @@ pub const Type = extern union {
640 const a_info = a.fnInfo();640 const a_info = a.fnInfo();
641 const b_info = b.fnInfo();641 const b_info = b.fnInfo();
642642
643 if (!eql(a_info.return_type, b_info.return_type, mod))643 if (a_info.return_type.tag() != .generic_poison and
644 b_info.return_type.tag() != .generic_poison and
645 !eql(a_info.return_type, b_info.return_type, mod))
644 return false;646 return false;
645647
646 if (a_info.is_var_args != b_info.is_var_args)648 if (a_info.is_var_args != b_info.is_var_args)
test/behavior/generics.zig+12
...@@ -405,3 +405,15 @@ test "null sentinel pointer passed as generic argument" {...@@ -405,3 +405,15 @@ test "null sentinel pointer passed as generic argument" {
405 };405 };
406 try S.doTheTest((@intToPtr([*:null]const [*c]const u8, 8)));406 try S.doTheTest((@intToPtr([*:null]const [*c]const u8, 8)));
407}407}
408
409test "generic function passed as comptime argument" {
410 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
411
412 const S = struct {
413 fn doMath(comptime f: fn (type, i32, i32) error{Overflow}!i32, a: i32, b: i32) !void {
414 const result = try f(i32, a, b);
415 try expect(result == 11);
416 }
417 };
418 try S.doMath(std.math.add, 5, 6);
419}