Fix error for named arguments-order with compile-time arguments #2212

This commit is contained in:
Christoffer Lerno
2025-06-16 23:56:03 +02:00
parent 779f548a00
commit e7ce79e731
4 changed files with 15 additions and 1 deletions

View File

@@ -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.

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -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;
}