aboutsummaryrefslogtreecommitdiff
path: root/src/check_stmt.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-08-07 16:29:00 +0100
committergingerBill <bill@gingerbill.org>2021-08-07 16:29:00 +0100
commit000bda841946c28bac9a94dd73651a4a1e1062f3 (patch)
tree266c746923fb2c5d6ea4771aa484ae2adecc8043 /src/check_stmt.cpp
parent423b84234791678647e726634a26676df3d289b2 (diff)
Reduce superfluous error messages for return statements expecting not-1 return values
Diffstat (limited to 'src/check_stmt.cpp')
-rw-r--r--src/check_stmt.cpp16
1 files changed, 15 insertions, 1 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<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];