Issue where trailing body argument was allowed without type even though the definition specified it #1879.

This commit is contained in:
Christoffer Lerno
2025-01-25 23:52:13 +01:00
parent 3e4f9e875f
commit 1f1c445a76
3 changed files with 24 additions and 0 deletions

View File

@@ -28,6 +28,7 @@
- Correctly check jump table size and be generous when compiling it #1877.
- Fix bug where .min/.max would fail on a distinct int #1888.
- Fix issue where compile time declarations in expression list would not be handled properly.
- Issue where trailing body argument was allowed without type even though the definition specified it #1879.
### Stdlib changes
- Added '%h' and '%H' for printing out binary data in hexadecimal using the formatter.

View File

@@ -2231,6 +2231,12 @@ bool sema_expr_analyse_macro_call(SemaContext *context, Expr *call_expr, Expr *s
TypeInfo *type_info = vartype(body_arg);
if (type_info && !sema_resolve_type_info(context, type_info, RESOLVE_TYPE_DEFAULT)) return false;
Type *type = type_info ? type_info->type : NULL;
if (!type && expected_type_info)
{
if (no_match_ref) goto NO_MATCH_REF;
RETURN_SEMA_ERROR(body_arg, "This parameter should be explicitly typed to %s but was untyped.",
type_quoted_error_string(expected_type_info->type));
}
if (type && expected_type_info && type->canonical != expected_type_info->type->canonical)
{
if (no_match_ref) goto NO_MATCH_REF;

View File

@@ -0,0 +1,17 @@
enum Foo
{
A,
}
fn void main()
{
@test(;$f) // #error: should be explicitly
{
};
}
macro @test(; @body(Foo $f))
{
@body(A);
}