From 000bda841946c28bac9a94dd73651a4a1e1062f3 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 7 Aug 2021 16:29:00 +0100 Subject: [PATCH] Reduce superfluous error messages for return statements expecting not-1 return values --- src/check_stmt.cpp | 16 +++++++++++++++- src/tokenizer.cpp | 6 +++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 8a7555945..236b5a9f5 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1445,6 +1445,17 @@ void check_block_stmt_for_errors(CheckerContext *ctx, Ast *body) { } } +bool all_operands_valid(Array 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]; diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 70de96dfb..8e42c649f 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -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) {