From 8e4d0ae4f5c50621a402192f2ff7f9b156030257 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Sat, 24 Sep 2022 00:08:42 +0300 Subject: [PATCH] Sema: avoid generic parameter error in nested function type Related to cd1833044ab7505bc101c85f59889bd3ea3fac80 Closes #12945 --- src/Sema.zig | 4 ++-- test/behavior.zig | 1 + test/behavior/bugs/12945.zig | 13 +++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/behavior/bugs/12945.zig diff --git a/src/Sema.zig b/src/Sema.zig index 81447d6361..a36e1d9a02 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -8180,7 +8180,7 @@ fn analyzeParameter( if (param.is_comptime and !Type.fnCallingConventionAllowsZigTypes(cc)) { return sema.fail(block, param_src, "comptime parameters not allowed in function with calling convention '{s}'", .{@tagName(cc)}); } - if (this_generic and !Type.fnCallingConventionAllowsZigTypes(cc)) { + if (this_generic and !sema.no_partial_func_ty and !Type.fnCallingConventionAllowsZigTypes(cc)) { return sema.fail(block, param_src, "generic parameters not allowed in function with calling convention '{s}'", .{@tagName(cc)}); } if (!param.ty.isValidParamType()) { @@ -8196,7 +8196,7 @@ fn analyzeParameter( }; return sema.failWithOwnedErrorMsg(msg); } - if (!Type.fnCallingConventionAllowsZigTypes(cc) and !try sema.validateExternType(block, param_src, param.ty, .param_ty)) { + if (!this_generic and !Type.fnCallingConventionAllowsZigTypes(cc) and !try sema.validateExternType(block, param_src, param.ty, .param_ty)) { const msg = msg: { const msg = try sema.errMsg(block, param_src, "parameter of type '{}' not allowed in function with calling convention '{s}'", .{ param.ty.fmt(sema.mod), @tagName(cc), diff --git a/test/behavior.zig b/test/behavior.zig index a4acb57124..648757d56f 100644 --- a/test/behavior.zig +++ b/test/behavior.zig @@ -96,6 +96,7 @@ test { _ = @import("behavior/bugs/12885.zig"); _ = @import("behavior/bugs/12911.zig"); _ = @import("behavior/bugs/12928.zig"); + _ = @import("behavior/bugs/12945.zig"); _ = @import("behavior/byteswap.zig"); _ = @import("behavior/byval_arg_var.zig"); _ = @import("behavior/call.zig"); diff --git a/test/behavior/bugs/12945.zig b/test/behavior/bugs/12945.zig new file mode 100644 index 0000000000..4eb7701ba4 --- /dev/null +++ b/test/behavior/bugs/12945.zig @@ -0,0 +1,13 @@ +const std = @import("std"); +const expect = std.testing.expect; + +fn A( + comptime T: type, + comptime destroycb: ?*const fn (?*T) callconv(.C) void, +) !void { + try expect(destroycb == null); +} + +test { + try A(u32, null); +}