mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fixed bug splatting constants into constants.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
9
test/test_suite/functions/global_splat.c3t
Normal file
9
test/test_suite/functions/global_splat.c3t
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user