diff options
| author | gingerBill <bill@gingerbill.org> | 2019-12-15 09:56:11 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-12-15 09:56:11 +0000 |
| commit | 8bec32477995f5a48fdb784bebe522015aedb036 (patch) | |
| tree | 02d2dc26a386dbfec9edcb6f21c14eb9828e579c /src/check_stmt.cpp | |
| parent | e6f26b9931af0b05b93447639fba7569691ac0d0 (diff) | |
Fix Duplicate integer switch case values incorrectly consider its absolute value #502
(Hashing proc was wrong for big ints)
Diffstat (limited to 'src/check_stmt.cpp')
| -rw-r--r-- | src/check_stmt.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index f7c5355c2..a2c158638 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -550,6 +550,7 @@ struct TypeAndToken { Token token; }; + void add_constant_switch_case(CheckerContext *ctx, Map<TypeAndToken> *seen, Operand operand, bool use_expr = true) { if (operand.mode != Addressing_Constant) { return; @@ -567,23 +568,25 @@ void add_constant_switch_case(CheckerContext *ctx, Map<TypeAndToken> *seen, Oper multi_map_get_all(seen, key, taps); for (isize i = 0; i < count; i++) { TypeAndToken tap = taps[i]; - if (are_types_identical(operand.type, tap.type)) { - TokenPos pos = tap.token.pos; - if (use_expr) { - gbString expr_str = expr_to_string(operand.expr); - error(operand.expr, - "Duplicate case '%s'\n" - "\tprevious case at %.*s(%td:%td)", - expr_str, - LIT(pos.file), pos.line, pos.column); - gb_string_free(expr_str); - } else { - error(operand.expr, - "Duplicate case found with previous case at %.*s(%td:%td)", - LIT(pos.file), pos.line, pos.column); - } - return; + if (!are_types_identical(operand.type, tap.type)) { + continue; } + + TokenPos pos = tap.token.pos; + if (use_expr) { + gbString expr_str = expr_to_string(operand.expr); + error(operand.expr, + "Duplicate case '%s'\n" + "\tprevious case at %.*s(%td:%td)", + expr_str, + LIT(pos.file), pos.line, pos.column); + gb_string_free(expr_str); + } else { + error(operand.expr, + "Duplicate case found with previous case at %.*s(%td:%td)", + LIT(pos.file), pos.line, pos.column); + } + return; } } |