Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7622,7 +7622,7 @@ fn instantiateGenericCall(
else if (call_src == .node_offset) .{ .call_arg = .{
.decl = block.src_decl,
.call_node_offset = call_src.node_offset.x,
.arg_index = @intCast(total_i),
.arg_index = @intCast(total_i - @intFromBool(bound_arg_src != null)),
} } else .unneeded;

const comptime_arg = callee.comptime_args.get(ip)[total_i];
Expand Down Expand Up @@ -9343,17 +9343,6 @@ fn zirParam(
assert(sema.inst_map.remove(inst));
}

if (sema.generic_owner != .none) {
if (try sema.typeHasOnePossibleValue(param_ty)) |opv| {
// In this case we are instantiating a generic function call with a non-comptime
// non-anytype parameter that ended up being a one-possible-type.
// We don't want the parameter to be part of the instantiated function type.
sema.inst_map.putAssumeCapacity(inst, Air.internedToRef(opv.toIntern()));
sema.comptime_args[param_index] = opv.toIntern();
return;
}
}

try block.params.append(sema.arena, .{
.ty = param_ty.toIntern(),
.is_comptime = comptime_syntax,
Expand Down
21 changes: 21 additions & 0 deletions test/cases/compile_errors/generic_method_call_invalid_coercion.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export fn callBoolMethod() void {
const s = S{};
s.boolMethod({});
}

export fn callVoidMethod() void {
const s = S{};
s.voidMethod(false);
}

const S = struct {
fn boolMethod(comptime _: @This(), _: bool) void {}
fn voidMethod(comptime _: @This(), _: void) void {}
};

// error
// backend=stage2
// target=native
//
// :3:18: error: expected type 'bool', found 'void'
// :8:18: error: expected type 'void', found 'bool'