diff --git a/releasenotes.md b/releasenotes.md index 418c9ab9f..641b5cc89 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -42,6 +42,7 @@ - Method on array slice caused segfault #2211. - In some cases, the compiler would dereference a compile time null. #2215 - Incorrect codegen if a macro ends with unreachable and is assigned to something. #2210 +- Fix error for named arguments-order with compile-time arguments #2212 ### Stdlib changes - Deprecate `String.is_zstr` and `String.quick_zstr` #2188. diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 6cf95168a..1ff93e304 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -425,6 +425,7 @@ typedef struct VarDecl_ bool is_self : 1; bool is_temp : 1; bool copy_const : 1; + bool defaulted : 1; union { Expr *init_expr; diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 6f76bb04e..78f8939d1 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -1501,6 +1501,7 @@ INLINE bool sema_set_default_argument(SemaContext *context, CalledDecl *callee, case VARDECL_PARAM_CT_TYPE: case VARDECL_PARAM_EXPR: *expr_ref = arg; + param->var.defaulted = true; if (parameter_checked) return true; return sema_analyse_parameter(context, arg, param, callee->definition, optional, no_match_ref, callee->macro, false); @@ -1718,7 +1719,7 @@ SPLAT_NORMAL:; } // 8e. We might have already set this parameter, that is not allowed. - if (actual_args[index] && actual_args[index]->expr_kind != EXPR_DEFAULT_ARG) + if (actual_args[index] && actual_args[index]->expr_kind != EXPR_DEFAULT_ARG && !param->var.defaulted) { RETURN_SEMA_ERROR(arg, "The parameter '%s' was already set.", param->name); } diff --git a/test/test_suite/macros/macro_arg_out_of_order.c3 b/test/test_suite/macros/macro_arg_out_of_order.c3 new file mode 100644 index 000000000..94b40ec51 --- /dev/null +++ b/test/test_suite/macros/macro_arg_out_of_order.c3 @@ -0,0 +1,11 @@ +module test_2212; + +macro test(int a = 123, int $b = 10, int c = -9,) +{ +} + +fn int main() +{ + test(a: 5, c: 5, $b: 5); // #error: Named arguments must always be declared + return 0; +}