Sema: avoid generic parameter error in nested function type

Related to cd1833044a
Closes #12945
This commit is contained in:
Veikka Tuominen
2022-09-24 00:08:42 +03:00
parent 3a5148112d
commit 8e4d0ae4f5
3 changed files with 16 additions and 2 deletions

View File

@@ -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),

View File

@@ -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");

View File

@@ -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);
}