diff options
| author | gingerBill <bill@gingerbill.org> | 2021-05-19 11:58:02 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-05-19 11:58:02 +0100 |
| commit | 3ac934dd15b59be670627213643e80c6d902fe4d (patch) | |
| tree | 1efa1d418ae735262fdae9c62b5254aa70329180 /src/check_stmt.cpp | |
| parent | 26ce40c188c31539cbf7f97cf2ad1bb81000bc55 (diff) | |
Add suggestion for unused expression on `x == y`
Expression is not used: 'x == 123'
Suggestion: Did you mean to do an assignment?
'x = 123;'
Diffstat (limited to 'src/check_stmt.cpp')
| -rw-r--r-- | src/check_stmt.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index ee60a4acd..a62b55ab2 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1436,6 +1436,28 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { gbString expr_str = expr_to_string(operand.expr); error(node, "Expression is not used: '%s'", expr_str); gb_string_free(expr_str); + if (operand.expr->kind == Ast_BinaryExpr) { + ast_node(be, BinaryExpr, operand.expr); + if (be->op.kind != Token_CmpEq) { + break; + } + + switch (be->left->tav.mode) { + case Addressing_Context: + case Addressing_Variable: + case Addressing_MapIndex: + case Addressing_SoaVariable: + { + gbString lhs = expr_to_string(be->left); + gbString rhs = expr_to_string(be->right); + error_line("\tSuggestion: Did you mean to do an assignment?\n", lhs, rhs); + error_line("\t '%s = %s;'\n", lhs, rhs); + gb_string_free(rhs); + gb_string_free(lhs); + } + break; + } + } break; } |