From db4dc114f291013683b8e7db3f90fd975b3bebd6 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 3 Jan 2025 15:01:24 +0100 Subject: [PATCH] $vasplat was allowed inside of a function when passed as an argument to a function. --- releasenotes.md | 1 + src/compiler/sema_expr.c | 2 +- .../test_suite/macros/vasplat_function_call.c3 | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/test_suite/macros/vasplat_function_call.c3 diff --git a/releasenotes.md b/releasenotes.md index 200e5ac53..48cb6021f 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -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. diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 42288c73f..d54f802a2 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -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; diff --git a/test/test_suite/macros/vasplat_function_call.c3 b/test/test_suite/macros/vasplat_function_call.c3 new file mode 100644 index 000000000..65e042202 --- /dev/null +++ b/test/test_suite/macros/vasplat_function_call.c3 @@ -0,0 +1,18 @@ +import std; + +def IList = List(); +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]); +}