Handle singular param count word in error messages (#6073)

This commit is contained in:
Ashish Shekar 2020-08-18 07:48:29 +05:30 committed by GitHub
parent d605af511a
commit 27cb23cbc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 12 deletions

View File

@ -393,7 +393,7 @@ fn analyzeInstParamType(mod: *Module, scope: *Scope, inst: *zir.Inst.ParamType)
// TODO support C-style var args
const param_count = fn_ty.fnParamLen();
if (arg_index >= param_count) {
return mod.fail(scope, inst.base.src, "arg index {} out of bounds; '{}' has {} arguments", .{
return mod.fail(scope, inst.base.src, "arg index {} out of bounds; '{}' has {} argument(s)", .{
arg_index,
fn_ty,
param_count,
@ -600,7 +600,7 @@ fn analyzeInstCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError
return mod.fail(
scope,
inst.positionals.func.src,
"expected at least {} arguments, found {}",
"expected at least {} argument(s), found {}",
.{ fn_params_len, call_params_len },
);
}
@ -610,7 +610,7 @@ fn analyzeInstCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError
return mod.fail(
scope,
inst.positionals.func.src,
"expected {} arguments, found {}",
"expected {} argument(s), found {}",
.{ fn_params_len, call_params_len },
);
}

View File

@ -6349,9 +6349,9 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
BuiltinFnEntry *builtin_fn = entry->value;
size_t actual_param_count = node->data.fn_call_expr.params.length;
if (builtin_fn->param_count != SIZE_MAX && builtin_fn->param_count != actual_param_count) {
if (builtin_fn->param_count != SIZE_MAX && builtin_fn->param_count != actual_param_count) {
add_node_error(irb->codegen, node,
buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,
buf_sprintf("expected %" ZIG_PRI_usize " argument(s), found %" ZIG_PRI_usize,
builtin_fn->param_count, actual_param_count));
return irb->codegen->invalid_inst_src;
}
@ -20186,7 +20186,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
if (fn_type_id->is_var_args) {
if (call_param_count < src_param_count) {
ErrorMsg *msg = ir_add_error_node(ira, source_node,
buf_sprintf("expected at least %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize "", src_param_count, call_param_count));
buf_sprintf("expected at least %" ZIG_PRI_usize " argument(s), found %" ZIG_PRI_usize "",
src_param_count, call_param_count));
if (fn_proto_node) {
add_error_note(ira->codegen, msg, fn_proto_node,
buf_sprintf("declared here"));
@ -20195,7 +20196,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
}
} else if (src_param_count != call_param_count) {
ErrorMsg *msg = ir_add_error_node(ira, source_node,
buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize "", src_param_count, call_param_count));
buf_sprintf("expected %" ZIG_PRI_usize " argument(s), found %" ZIG_PRI_usize "",
src_param_count, call_param_count));
if (fn_proto_node) {
add_error_note(ira->codegen, msg, fn_proto_node,
buf_sprintf("declared here"));
@ -30127,7 +30129,7 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy
return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_anytype);
}
ir_add_error(ira, &arg_index_inst->base,
buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " arguments",
buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " argument(s)",
arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count));
return ira->codegen->invalid_inst_gen;
}

View File

@ -705,7 +705,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ for (arr) |bits| _ = @popCount(bits);
\\}
, &[_][]const u8{
"tmp.zig:3:26: error: expected 2 arguments, found 1",
"tmp.zig:3:26: error: expected 2 argument(s), found 1",
});
cases.addTest("@call rejects non comptime-known fn - always_inline",
@ -4103,7 +4103,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\}
\\fn b(a: i32, b: i32, c: i32) void { }
, &[_][]const u8{
"tmp.zig:2:6: error: expected 3 arguments, found 1",
"tmp.zig:2:6: error: expected 3 argument(s), found 1",
});
cases.add("invalid type",
@ -4716,7 +4716,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\
\\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
, &[_][]const u8{
"tmp.zig:20:34: error: expected 1 arguments, found 0",
"tmp.zig:20:34: error: expected 1 argument(s), found 0",
});
cases.add("missing function name",
@ -5498,7 +5498,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\}
\\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
, &[_][]const u8{
"tmp.zig:6:15: error: expected 2 arguments, found 3",
"tmp.zig:6:15: error: expected 2 argument(s), found 3",
});
cases.add("assign through constant pointer",