diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-08-24 19:52:52 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-08-24 21:31:02 +0300 |
| commit | cd1833044ab7505bc101c85f59889bd3ea3fac80 (patch) | |
| tree | d7958e47cab0b196cc2d731b74938343619a188c /test | |
| parent | d515d37934476365929401a0ba7e5639b09a648a (diff) | |
| download | zig-cd1833044ab7505bc101c85f59889bd3ea3fac80.tar.gz zig-cd1833044ab7505bc101c85f59889bd3ea3fac80.zip | |
Sema: do not construct nested partial function types
Closes #12616
Diffstat (limited to 'test')
| -rw-r--r-- | test/behavior/generics.zig | 15 | ||||
| -rw-r--r-- | test/cases/compile_errors/comptime_parameter_not_declared_as_such.zig | 7 |
2 files changed, 19 insertions, 3 deletions
diff --git a/test/behavior/generics.zig b/test/behavior/generics.zig index d930fb7d27..ba4bca0c1a 100644 --- a/test/behavior/generics.zig +++ b/test/behavior/generics.zig @@ -342,3 +342,18 @@ test "generic instantiation of tagged union with only one field" { try expect(S.foo(.{ .s = "a" }) == 1); try expect(S.foo(.{ .s = "ab" }) == 2); } + +test "nested generic function" { + const S = struct { + fn foo(comptime T: type, callback: *const fn (user_data: T) anyerror!void, data: T) anyerror!void { + try callback(data); + } + fn bar(a: u32) anyerror!void { + try expect(a == 123); + } + + fn g(_: *const fn (anytype) void) void {} + }; + try expect(@typeInfo(@TypeOf(S.g)).Fn.is_generic); + try S.foo(u32, S.bar, 123); +} diff --git a/test/cases/compile_errors/comptime_parameter_not_declared_as_such.zig b/test/cases/compile_errors/comptime_parameter_not_declared_as_such.zig index e4d9eed079..008d14f2fc 100644 --- a/test/cases/compile_errors/comptime_parameter_not_declared_as_such.zig +++ b/test/cases/compile_errors/comptime_parameter_not_declared_as_such.zig @@ -1,5 +1,6 @@ fn f(_: anytype) void {} -fn g(h: *const fn (anytype) void) void { +const T = *const fn (anytype) void; +fn g(h: T) void { h({}); } pub export fn entry() void { @@ -19,5 +20,5 @@ pub export fn entry1() void { // backend=stage2 // target=native // -// :2:6: error: parameter of type '*const fn(anytype) void' must be declared comptime -// :9:34: error: parameter of type 'comptime_int' must be declared comptime +// :3:6: error: parameter of type '*const fn(anytype) void' must be declared comptime +// :10:34: error: parameter of type 'comptime_int' must be declared comptime |
