Support []int{multiple_returns(), 123}

This commit is contained in:
gingerBill
2026-04-21 17:45:36 +01:00
parent b1e8ec5e64
commit ef275c5c0e
3 changed files with 89 additions and 33 deletions

View File

@@ -10630,8 +10630,9 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
cl->max_count = max;
} else {
isize index = 0;
for (; index < cl->elems.count; index++) {
for (isize index = 0; index < cl->elems.count; index++) {
defer (max += 1);
Ast *e = cl->elems[index];
if (e == nullptr) {
error(node, "Invalid literal element");
@@ -10648,17 +10649,25 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
}
Operand operand = {};
check_expr_with_type_hint(c, &operand, e, elem_type);
check_assignment(c, &operand, elem_type, context_name);
check_multi_expr_with_type_hint(c, &operand, e, elem_type);
if (is_type_tuple(operand.type)) {
is_constant = false;
TypeTuple *tt = &operand.type->Tuple;
for_array(jj, tt->variables) {
Operand oo = operand;
oo.type = tt->variables[jj]->type;
check_assignment(c, &oo, elem_type, context_name);
}
if (is_constant) {
is_constant = check_is_operand_compound_lit_constant(c, &operand, elem_type);
max += tt->variables.count-1;
} else {
check_assignment(c, &operand, elem_type, context_name);
if (is_constant) {
is_constant = check_is_operand_compound_lit_constant(c, &operand, elem_type);
}
}
}
if (max < index) {
max = index;
}
}
@@ -10679,6 +10688,12 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
error(node, "Expected %lld values for this #soa array literal, got %lld", cast(long long)t->Struct.soa_count, cast(long long)max);
}
}
} else if (t->kind == Type_FixedCapacityDynamicArray) {
if (max > t->FixedCapacityDynamicArray.capacity) {
error(node, "Expected a maximum of %lld values for this fixed capacity dynamic array, got %lld",
cast(long long)t->FixedCapacityDynamicArray.capacity,
cast(long long)max);
}
}
@@ -10704,6 +10719,8 @@ gb_internal ExprKind check_compound_literal(CheckerContext *c, Operand *o, Ast *
}
}
cl->max_count = max;
break;
}