diff options
| author | gingerBill <bill@gingerbill.org> | 2021-08-16 11:08:37 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-08-16 11:08:37 +0100 |
| commit | 4c306a6f9958a01302cf09fdff8f7d4ff143c605 (patch) | |
| tree | 5506e971194efe96014889d5e71575cda37a8af3 /src/check_stmt.cpp | |
| parent | 0996cc82a7e03de9217135b93be5fc3992666ee4 (diff) | |
Correct `or_return` logic for debug printing and expression is not used checking
Diffstat (limited to 'src/check_stmt.cpp')
| -rw-r--r-- | src/check_stmt.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 236b5a9f5..6c5da5197 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1456,6 +1456,21 @@ bool all_operands_valid(Array<Operand> const &operands) { return true; } +Ast *strip_or_return_expr(Ast *node) { + for (;;) { + if (node == nullptr) { + return node; + } + if (node->kind == Ast_OrReturnExpr) { + node = node->OrReturnExpr.expr; + } else if (node->kind == Ast_ParenExpr) { + node = node->ParenExpr.expr; + } else { + return node; + } + } +} + void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { u32 mod_flags = flags & (~Stmt_FallthroughAllowed); switch (node->kind) { @@ -1480,8 +1495,10 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { if (kind == Expr_Stmt) { return; } - if (operand.expr->kind == Ast_CallExpr) { - AstCallExpr *ce = &operand.expr->CallExpr; + Ast *expr = strip_or_return_expr(operand.expr); + + if (expr->kind == Ast_CallExpr) { + AstCallExpr *ce = &expr->CallExpr; Type *t = type_of_expr(ce->proc); if (is_type_proc(t)) { if (t->Proc.require_results) { @@ -1491,8 +1508,8 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { } } return; - } else if (operand.expr->kind == Ast_SelectorCallExpr) { - AstSelectorCallExpr *se = &operand.expr->SelectorCallExpr; + } else if (expr->kind == Ast_SelectorCallExpr) { + AstSelectorCallExpr *se = &expr->SelectorCallExpr; ast_node(ce, CallExpr, se->call); Type *t = type_of_expr(ce->proc); if (is_type_proc(t)) { |