authorgravatar for ckrackerx15@gmail.comAshish Shekar <ckrackerx15@gmail.com> 2020-08-18 07:48:29+05:30
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-08-17 22:18:29-04:00
log27cb23cbc5fe35d0eae8494006ba93111bd2bde6
treed561c9284e24815a06f43a4eaad62cf24f21cbf5
parentd605af511a9af5d987a9e2276c2ed9a1b4e951c7
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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


3 files changed, 14 insertions(+), 12 deletions(-)

src-self-hosted/zir_sema.zig+3-3
......@@ -393,7 +393,7 @@ fn analyzeInstParamType(mod: *Module, scope: *Scope, inst: *zir.Inst.ParamType)
393393 // TODO support C-style var args
394394 const param_count = fn_ty.fnParamLen();
395395 if (arg_index >= param_count) {
396 return mod.fail(scope, inst.base.src, "arg index {} out of bounds; '{}' has {} arguments", .{
396 return mod.fail(scope, inst.base.src, "arg index {} out of bounds; '{}' has {} argument(s)", .{
397397 arg_index,
398398 fn_ty,
399399 param_count,
......@@ -600,7 +600,7 @@ fn analyzeInstCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError
600600 return mod.fail(
601601 scope,
602602 inst.positionals.func.src,
603 "expected at least {} arguments, found {}",
603 "expected at least {} argument(s), found {}",
604604 .{ fn_params_len, call_params_len },
605605 );
606606 }
......@@ -610,7 +610,7 @@ fn analyzeInstCall(mod: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerError
610610 return mod.fail(
611611 scope,
612612 inst.positionals.func.src,
613 "expected {} arguments, found {}",
613 "expected {} argument(s), found {}",
614614 .{ fn_params_len, call_params_len },
615615 );
616616 }
src/ir.cpp+7-5
......@@ -6349,9 +6349,9 @@ static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNod
63496349 BuiltinFnEntry *builtin_fn = entry->value;
63506350 size_t actual_param_count = node->data.fn_call_expr.params.length;
63516351
6352 if (builtin_fn->param_count != SIZE_MAX && builtin_fn->param_count != actual_param_count) {
6352 if (builtin_fn->param_count != SIZE_MAX && builtin_fn->param_count != actual_param_count) {
63536353 add_node_error(irb->codegen, node,
6354 buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,
6354 buf_sprintf("expected %" ZIG_PRI_usize " argument(s), found %" ZIG_PRI_usize,
63556355 builtin_fn->param_count, actual_param_count));
63566356 return irb->codegen->invalid_inst_src;
63576357 }
......@@ -20186,7 +20186,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
2018620186 if (fn_type_id->is_var_args) {
2018720187 if (call_param_count < src_param_count) {
2018820188 ErrorMsg *msg = ir_add_error_node(ira, source_node,
20189 buf_sprintf("expected at least %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize "", src_param_count, call_param_count));
20189 buf_sprintf("expected at least %" ZIG_PRI_usize " argument(s), found %" ZIG_PRI_usize "",
20190 src_param_count, call_param_count));
2019020191 if (fn_proto_node) {
2019120192 add_error_note(ira->codegen, msg, fn_proto_node,
2019220193 buf_sprintf("declared here"));
......@@ -20195,7 +20196,8 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
2019520196 }
2019620197 } else if (src_param_count != call_param_count) {
2019720198 ErrorMsg *msg = ir_add_error_node(ira, source_node,
20198 buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize "", src_param_count, call_param_count));
20199 buf_sprintf("expected %" ZIG_PRI_usize " argument(s), found %" ZIG_PRI_usize "",
20200 src_param_count, call_param_count));
2019920201 if (fn_proto_node) {
2020020202 add_error_note(ira->codegen, msg, fn_proto_node,
2020120203 buf_sprintf("declared here"));
......@@ -30127,7 +30129,7 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy
3012730129 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_anytype);
3012830130 }
3012930131 ir_add_error(ira, &arg_index_inst->base,
30130 buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " arguments",
30132 buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " argument(s)",
3013130133 arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count));
3013230134 return ira->codegen->invalid_inst_gen;
3013330135 }
test/compile_errors.zig+4-4
......@@ -705,7 +705,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
705705 \\ for (arr) |bits| _ = @popCount(bits);
706706 \\}
707707 , &[_][]const u8{
708 "tmp.zig:3:26: error: expected 2 arguments, found 1",
708 "tmp.zig:3:26: error: expected 2 argument(s), found 1",
709709 });
710710
711711 cases.addTest("@call rejects non comptime-known fn - always_inline",
......@@ -4103,7 +4103,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
41034103 \\}
41044104 \\fn b(a: i32, b: i32, c: i32) void { }
41054105 , &[_][]const u8{
4106 "tmp.zig:2:6: error: expected 3 arguments, found 1",
4106 "tmp.zig:2:6: error: expected 3 argument(s), found 1",
41074107 });
41084108
41094109 cases.add("invalid type",
......@@ -4716,7 +4716,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
47164716 \\
47174717 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
47184718 , &[_][]const u8{
4719 "tmp.zig:20:34: error: expected 1 arguments, found 0",
4719 "tmp.zig:20:34: error: expected 1 argument(s), found 0",
47204720 });
47214721
47224722 cases.add("missing function name",
......@@ -5498,7 +5498,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
54985498 \\}
54995499 \\export fn entry() usize { return @sizeOf(@TypeOf(f)); }
55005500 , &[_][]const u8{
5501 "tmp.zig:6:15: error: expected 2 arguments, found 3",
5501 "tmp.zig:6:15: error: expected 2 argument(s), found 3",
55025502 });
55035503
55045504 cases.add("assign through constant pointer",