authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-24 00:08:42+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-09-24 15:15:36+03:00
log8e4d0ae4f5c50621a402192f2ff7f9b156030257
tree7f957913bc7191f3f61c5ef2e642fa2376017886
parent3a5148112d4ea8a3650e5163c99b7978c784d0a5

Sema: avoid generic parameter error in nested function type

Related to cd1833044ab7505bc101c85f59889bd3ea3fac80 Closes #12945

3 files changed, 16 insertions(+), 2 deletions(-)

src/Sema.zig+2-2
......@@ -8180,7 +8180,7 @@ fn analyzeParameter(
81808180 if (param.is_comptime and !Type.fnCallingConventionAllowsZigTypes(cc)) {
81818181 return sema.fail(block, param_src, "comptime parameters not allowed in function with calling convention '{s}'", .{@tagName(cc)});
81828182 }
8183 if (this_generic and !Type.fnCallingConventionAllowsZigTypes(cc)) {
8183 if (this_generic and !sema.no_partial_func_ty and !Type.fnCallingConventionAllowsZigTypes(cc)) {
81848184 return sema.fail(block, param_src, "generic parameters not allowed in function with calling convention '{s}'", .{@tagName(cc)});
81858185 }
81868186 if (!param.ty.isValidParamType()) {
......@@ -8196,7 +8196,7 @@ fn analyzeParameter(
81968196 };
81978197 return sema.failWithOwnedErrorMsg(msg);
81988198 }
8199 if (!Type.fnCallingConventionAllowsZigTypes(cc) and !try sema.validateExternType(block, param_src, param.ty, .param_ty)) {
8199 if (!this_generic and !Type.fnCallingConventionAllowsZigTypes(cc) and !try sema.validateExternType(block, param_src, param.ty, .param_ty)) {
82008200 const msg = msg: {
82018201 const msg = try sema.errMsg(block, param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{
82028202 param.ty.fmt(sema.mod), @tagName(cc),
test/behavior.zig+1
......@@ -96,6 +96,7 @@ test {
9696 _ = @import("behavior/bugs/12885.zig");
9797 _ = @import("behavior/bugs/12911.zig");
9898 _ = @import("behavior/bugs/12928.zig");
99 _ = @import("behavior/bugs/12945.zig");
99100 _ = @import("behavior/byteswap.zig");
100101 _ = @import("behavior/byval_arg_var.zig");
101102 _ = @import("behavior/call.zig");
test/behavior/bugs/12945.zig created+13
......@@ -0,0 +1,13 @@
1const std = @import("std");
2const expect = std.testing.expect;
3
4fn A(
5 comptime T: type,
6 comptime destroycb: ?*const fn (?*T) callconv(.C) void,
7) !void {
8 try expect(destroycb == null);
9}
10
11test {
12 try A(u32, null);
13}