diff --git a/releasenotes.md b/releasenotes.md index 0c5afb4a6..3489cb9b8 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -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. diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 8e74da245..7588fd84b 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -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; diff --git a/test/test_suite/macros/macro_body_missing_type.c3 b/test/test_suite/macros/macro_body_missing_type.c3 new file mode 100644 index 000000000..570345205 --- /dev/null +++ b/test/test_suite/macros/macro_body_missing_type.c3 @@ -0,0 +1,17 @@ +enum Foo +{ + A, +} + +fn void main() +{ + @test(;$f) // #error: should be explicitly + { + + }; +} + +macro @test(; @body(Foo $f)) +{ + @body(A); +} \ No newline at end of file