- Allow inferred type on body parameters. E.g. @stack_mem(1024; alloc) { ... };

This commit is contained in:
Christoffer Lerno
2025-03-18 15:40:26 +01:00
parent 72608ce01d
commit 84753bde6d
3 changed files with 6 additions and 12 deletions

View File

@@ -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).

View File

@@ -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)
{

View File

@@ -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'
};
}