diff --git a/releasenotes.md b/releasenotes.md index 94a5c45d4..080f4ca46 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -39,6 +39,7 @@ - `!!foo` now works same as as `! ! foo`. - Temp allocator now supports more than 2 in-flight stacks. - Printing stacktrace uses its own temp allocator. +- Allow inferred type on body parameters. E.g. `@stack_mem(1024; alloc) { ... };` ### Fixes - Fix address sanitizer to work on MachO targets (e.g. MacOS). diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 5ed4754b0..472de46c9 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -2132,14 +2132,8 @@ bool sema_expr_analyse_macro_call(SemaContext *context, Expr *call_expr, Expr *s continue; case VARDECL_PARAM_CT: case VARDECL_PARAM_EXPR: - // Optional typing - break; case VARDECL_PARAM: - // Mandatory typing - if (!body_arg->var.type_info) - { - RETURN_SEMA_ERROR(body_arg, "Expected a type parameter before this variable name."); - } + // Optional typing break; default: UNREACHABLE @@ -2150,9 +2144,7 @@ bool sema_expr_analyse_macro_call(SemaContext *context, Expr *call_expr, Expr *s 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)); + type = expected_type_info->type; } if (type && expected_type_info && type->canonical != expected_type_info->type->canonical) { diff --git a/test/test_suite/macros/macro_body_missing_type.c3 b/test/test_suite/macros/macro_body_missing_type.c3 index 570345205..a2a844257 100644 --- a/test/test_suite/macros/macro_body_missing_type.c3 +++ b/test/test_suite/macros/macro_body_missing_type.c3 @@ -5,9 +5,10 @@ enum Foo fn void main() { - @test(;$f) // #error: should be explicitly + @test(;$f) { - + Foo x = $f; + int xd = $f; // #error: It is not possible to cast 'Foo' to 'int' }; }