Fix polymorphic record "too few" lacking error message

This commit is contained in:
gingerBill
2021-05-31 20:33:14 +01:00
parent bc4591fc1e
commit 4d80f8598d
3 changed files with 16 additions and 3 deletions

View File

@@ -5286,8 +5286,8 @@ CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *oper
TypeTuple *tuple = get_record_polymorphic_params(original_type);
isize param_count = tuple->variables.count;
isize minimum_param_count = param_count;
for (minimum_param_count = tuple->variables.count-1; minimum_param_count >= 0; minimum_param_count--) {
Entity *e = tuple->variables[minimum_param_count];
for (; minimum_param_count > 0; minimum_param_count--) {
Entity *e = tuple->variables[minimum_param_count-1];
if (e->kind != Entity_Constant) {
break;
}
@@ -5296,6 +5296,7 @@ CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *oper
}
}
Array<Operand> ordered_operands = operands;
if (!named_fields) {
ordered_operands = array_make<Operand>(permanent_allocator(), param_count);
@@ -5367,6 +5368,13 @@ CallArgumentError check_polymorphic_record_type(CheckerContext *c, Operand *oper
return err;
}
while (ordered_operands.count >= 0) {
if (ordered_operands[ordered_operands.count-1].expr != nullptr) {
break;
}
array_pop(&ordered_operands);
}
if (minimum_param_count != param_count) {
if (param_count < ordered_operands.count) {
error(call, "Too many polymorphic type arguments, expected a maximum of %td, got %td", param_count, ordered_operands.count);