Sema: fix condition for omitting comptime arg from function type

Closes #14164
This commit is contained in:
Veikka Tuominen
2023-01-10 14:04:38 +02:00
parent ad259736e2
commit 8b1780d939
2 changed files with 25 additions and 1 deletions

View File

@@ -9005,7 +9005,7 @@ fn zirParam(
else => |e| return e,
} or comptime_syntax;
if (sema.inst_map.get(inst)) |arg| {
if (is_comptime) {
if (is_comptime and sema.preallocated_new_func != null) {
// We have a comptime value for this parameter so it should be elided from the
// function type of the function instruction in this block.
const coerced_arg = try sema.coerce(block, param_ty, arg, src);

View File

@@ -0,0 +1,24 @@
pub fn sort(
comptime T: type,
items: []T,
context: anytype,
lessThan: *const fn (context: @TypeOf(context), lhs: T, rhs: T) u32,
) void {
_ = items;
_ = lessThan;
}
fn foo(_: void, _: u8, _: u8) u32 {
return 0;
}
pub export fn entry() void {
var items = [_]u8{ 3, 5, 7, 2, 6, 9, 4 };
sort(u8, &items, void, foo);
}
// error
// backend=llvm
// target=native
//
// :15:28: error: expected type '*const fn(comptime type, u8, u8) u32', found '*const fn(void, u8, u8) u32'
// :15:28: note: pointer type child 'fn(void, u8, u8) u32' cannot cast into pointer type child 'fn(comptime type, u8, u8) u32'
// :15:28: note: non-generic function cannot cast into a generic function