Non-const macros may not return untyped lists.

This commit is contained in:
Christoffer Lerno
2025-07-03 15:45:14 +02:00
parent 10e11fb742
commit ee1ed73fc5
3 changed files with 22 additions and 4 deletions

View File

@@ -18,6 +18,7 @@
- Missing bounds check on upper bound with const ranges `foo[1:3]`.
- Check up the hierarchy when considering if an interface cast is valid #2267.
- Fix issue with labelled break inside of a $switch.
- Non-const macros may not return untyped lists.
### Stdlib changes

View File

@@ -2859,11 +2859,14 @@ EXIT:
}
sema_context_destroy(&macro_context);
call_expr->resolve_status = RESOLVE_DONE;
if (is_always_const && !expr_is_runtime_const(call_expr))
if (!expr_is_runtime_const(call_expr))
{
SEMA_ERROR(call_expr, "The macro failed to fold to a constant value, despite being '@const'.");
SEMA_NOTE(decl, "The macro was declared here.");
return false;
if (is_always_const)
{
SEMA_ERROR(call_expr, "The macro failed to fold to a constant value, despite being '@const'.");
SEMA_NOTE(decl, "The macro was declared here.");
return false;
}
}
return true;
EXIT_FAIL:

View File

@@ -0,0 +1,14 @@
struct Test
{
struct { int a; }
}
macro test(int x)
{
return {{}};
}
fn int main()
{
Test a = test(3);
return 0;
}