Reduce superfluous error messages for return statements expecting not-1 return values

This commit is contained in:
gingerBill
2021-08-07 16:29:00 +01:00
parent 423b842347
commit 000bda8419
2 changed files with 20 additions and 2 deletions
+15 -1
View File
@@ -1445,6 +1445,17 @@ void check_block_stmt_for_errors(CheckerContext *ctx, Ast *body) {
}
}
bool all_operands_valid(Array<Operand> const &operands) {
if (any_errors()) {
for_array(i, operands) {
if (operands[i].type == t_invalid) {
return false;
}
}
}
return true;
}
void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
u32 mod_flags = flags & (~Stmt_FallthroughAllowed);
switch (node->kind) {
@@ -1699,7 +1710,10 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
} else if (has_named_results && operands.count == 0) {
// Okay
} else if (operands.count != result_count) {
error(node, "Expected %td return values, got %td", result_count, operands.count);
// Ignore error message as it has most likely already been reported
if (all_operands_valid(operands)) {
error(node, "Expected %td return values, got %td", result_count, operands.count);
}
} else {
for (isize i = 0; i < result_count; i++) {
Entity *e = pt->results->Tuple.variables[i];
+5 -1
View File
@@ -278,7 +278,11 @@ gb_global ErrorCollector global_error_collector;
bool any_errors(void) {
return global_error_collector.error_buffer.count > 0;
bool any_errors = false;
mutex_lock(&global_error_collector.block_mutex);
any_errors = global_error_collector.error_buffer.count > 0;
mutex_unlock(&global_error_collector.block_mutex);
return any_errors;
}
void init_global_error_collector(void) {