$vasplat was allowed inside of a function when passed as an argument to a function.

This commit is contained in:
Christoffer Lerno
2025-01-03 15:01:24 +01:00
parent a7f363ea43
commit db4dc114f2
3 changed files with 20 additions and 1 deletions

View File

@@ -47,6 +47,7 @@
- `$defined` in a global scope should accept testing normal macros.
- Assert on add to uninitialized ct variable #1765.
- Dynamic function lookup fails after changing type without dummy anycast #1761
- $vasplat was allowed inside of a function when passed as an argument to a function.
### Stdlib changes
- Increase BitWriter.write_bits limit up to 32 bits.

View File

@@ -1586,7 +1586,7 @@ INLINE bool sema_call_evaluate_arguments(SemaContext *context, CalledDecl *calle
Expr *arg = args[i];
if (i > 0) last = args[i - 1];
ASSERT0(expr_ok(arg));
if (arg->expr_kind == EXPR_VASPLAT)
if (arg->expr_kind == EXPR_VASPLAT && context->current_macro)
{
Expr **new_args = sema_vasplat_insert(context, args, arg, i);
if (!new_args) return false;

View File

@@ -0,0 +1,18 @@
import std;
def IList = List(<int>);
fn IList IList.new(...) @operator(construct)
{
IList l;
l.new_init($vasplat); // #error: can only be used inside
return l;
}
fn void main()
{
IList a = IList.new(123, 123, 123, 123, 123, 123, 123, 134);
a.push(567);
io::printfn("%s", a[0]);
}