Fixed bug splatting constants into constants.

This commit is contained in:
Christoffer Lerno
2025-07-11 01:55:09 +02:00
parent 02c0db7b8b
commit cdd530d807
3 changed files with 16 additions and 1 deletions

View File

@@ -47,6 +47,7 @@
- `$foo` variables could be assigned non-compile time values.
- `$foo[0] = ...` was incorrectly requiring that the assigned values were compile time constants.
- "Inlined at" would sometimes show the current location.
- Fixed bug splatting constants into constants.
### Stdlib changes
- Improve contract for readline. #2280

View File

@@ -1663,7 +1663,7 @@ INLINE bool sema_set_default_argument(SemaContext *context, CalledDecl *callee,
INLINE Expr **sema_splat_arraylike_insert(SemaContext *context, Expr **args, Expr *arg, ArraySize len, ArrayIndex index)
{
args = sema_prepare_splat_insert(args, len, index);
if (expr_is_const(arg))
if (sema_cast_const(arg))
{
for (ArrayIndex i = 0; i < len; i++)
{
@@ -1675,6 +1675,11 @@ INLINE Expr **sema_splat_arraylike_insert(SemaContext *context, Expr **args, Exp
}
return args;
}
if (context->call_env.kind != CALL_ENV_FUNCTION)
{
SEMA_ERROR(arg, "Cannot splat a non-constant value in a global context.");
return NULL;
}
Decl *temp = decl_new_generated_var(arg->type, VARDECL_LOCAL, arg->span);
Expr *decl_expr = expr_generate_decl(temp, arg);
Expr *two = expr_new_expr(EXPR_TWO, arg);

View File

@@ -0,0 +1,9 @@
const int[*] A = { 1, 2, 3 };
const int[*] B = { 4, 5, 6 };
const int[*] C = { ...A, ...B };
fn int main()
{
return 0;
}