Error when using named argument on trailing macro body expansion #2139.

This commit is contained in:
Christoffer Lerno
2025-05-17 23:50:15 +02:00
parent 082457c5fb
commit 498803e9ba
3 changed files with 15 additions and 0 deletions

View File

@@ -31,6 +31,7 @@
- Incorrect parsing of ad hoc generic types, like `Foo{int}****` #2140. - Incorrect parsing of ad hoc generic types, like `Foo{int}****` #2140.
- $define did not correctly handle generic types #2140. - $define did not correctly handle generic types #2140.
- Incorrect parsing of call attributes #2144. - Incorrect parsing of call attributes #2144.
- Error when using named argument on trailing macro body expansion #2139.
### Stdlib changes ### Stdlib changes
- Added `String.quick_ztr` and `String.is_zstr` - Added `String.quick_ztr` and `String.is_zstr`

View File

@@ -1290,6 +1290,11 @@ static bool sema_analyse_parameter(SemaContext *context, Expr *arg, Decl *param,
{ {
case VARDECL_PARAM: case VARDECL_PARAM:
// foo // foo
if (arg->expr_kind == EXPR_NAMED_ARGUMENT)
{
// This only happens in body arguments
RETURN_SEMA_ERROR(arg, "Named arguments are not supported for body parameters.");
}
if (!sema_analyse_expr_rhs(context, type, arg, true, no_match_ref, false)) return false; if (!sema_analyse_expr_rhs(context, type, arg, true, no_match_ref, false)) return false;
if (IS_OPTIONAL(arg)) *optional_ref = true; if (IS_OPTIONAL(arg)) *optional_ref = true;
switch (sema_resolve_storage_type(context, arg->type)) switch (sema_resolve_storage_type(context, arg->type))

View File

@@ -0,0 +1,9 @@
macro @foo(; @body(int arg))
{
@body(arg: 0); // #error: Named arguments are not supported for body parameters
}
fn void main()
{
@foo(; int arg) {};
}