mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix error for named arguments-order with compile-time arguments #2212
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
11
test/test_suite/macros/macro_arg_out_of_order.c3
Normal file
11
test/test_suite/macros/macro_arg_out_of_order.c3
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user