diff --git a/releasenotes.md b/releasenotes.md index bdffe6261..08fdc93cd 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -50,6 +50,7 @@ - "Inlined at" would sometimes show the current location. - Fixed bug splatting constants into constants. - Resize bug when resizing memory down in ArenaAllocator, DynamicArenaAllocator, BackedArenaAllocator. +- Error message for missing arg incorrect for methods with zero args #2296. ### Stdlib changes - Improve contract for readline. #2280 diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 977c27781..d2ad30c39 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -1999,7 +1999,8 @@ SPLAT_NORMAL:; { int missing = 1; for (int j = i + 1; j < func_param_count; j++) if (!actual_args[j]) missing++; - if (vec_size(callee->params) == 1) + int implicit_args = callee->struct_var ? 1 : 0; + if (vec_size(callee->params) == 1 + implicit_args) { if (param->type) { @@ -2014,7 +2015,7 @@ SPLAT_NORMAL:; print_error_after(last->span, "Expected '%s: ...' after this argument.", param->name); RETURN_NOTE_FUNC_DEFINITION; } - if (!num_args) + if (num_args == implicit_args) { if (missing != needed) { diff --git a/test/test_suite/methods/method_error_args.c3 b/test/test_suite/methods/method_error_args.c3 new file mode 100644 index 000000000..93277cfec --- /dev/null +++ b/test/test_suite/methods/method_error_args.c3 @@ -0,0 +1,10 @@ +module test; +import std; + +fn void String.hello(self, int a, int b) {} +fn void main() +{ + String s = "foek"; + s.hello(); // #error: 'hello' expects 2 parameter(s), but none was provided + s.hello(1); // #error: 1 more argument was expected after this one, did you forget it? +}