Browse Source

Handle concatenation at the end

gingerBill 1 day ago
parent
commit
26b3a4d182
1 changed files with 18 additions and 6 deletions
  1. 18 6
      src/check_builtin.cpp

+ 18 - 6
src/check_builtin.cpp

@@ -4923,11 +4923,6 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
 
 
 		Type *elem_type = base_any_array_type(lhs.type);
 		Type *elem_type = base_any_array_type(lhs.type);
 
 
-		Array<Ast *> new_elems = {};
-		array_init(&new_elems, heap_allocator());
-
-		array_add_elems(&new_elems, lhs_cl->elems.data, lhs_cl->elems.count);
-
 		for (isize i = 1; i < ce->args.count; i++) {
 		for (isize i = 1; i < ce->args.count; i++) {
 			Operand extra = {};
 			Operand extra = {};
 			if (is_type_slice(lhs.type)) {
 			if (is_type_slice(lhs.type)) {
@@ -4988,8 +4983,25 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
 					return false;
 					return false;
 				}
 				}
 			}
 			}
+		}
+
+		isize count_needed = 0;
 
 
-			array_add_elems(&new_elems, extra_cl->elems.data, extra_cl->elems.count);
+		for (Ast *arg : ce->args) {
+			ExactValue value = arg->tav.value;
+			GB_ASSERT(value.kind == ExactValue_Compound);
+			ast_node(cl, CompoundLit, value.value_compound);
+			count_needed += cl->elems.count;
+		}
+
+		Array<Ast *> new_elems = {};
+		array_init(&new_elems, permanent_allocator(), 0, count_needed);
+
+		for (Ast *arg : ce->args) {
+			ExactValue value = arg->tav.value;
+			GB_ASSERT(value.kind == ExactValue_Compound);
+			ast_node(cl, CompoundLit, value.value_compound);
+			array_add_elems(&new_elems, cl->elems.data, cl->elems.count);
 		}
 		}
 
 
 		Ast *new_compound_lit = ast_compound_lit(lhs.expr->file(), nullptr, new_elems, ast_token(lhs.expr), ast_end_token(ce->args[ce->args.count-1]));
 		Ast *new_compound_lit = ast_compound_lit(lhs.expr->file(), nullptr, new_elems, ast_token(lhs.expr), ast_end_token(ce->args[ce->args.count-1]));