aboutsummaryrefslogtreecommitdiff
path: root/src/check_stmt.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-02-17 18:22:43 +0000
committergingerBill <bill@gingerbill.org>2018-02-17 18:22:43 +0000
commitc341597657d92834209b720efc54011bf0179828 (patch)
treec28dc29ee9a5aa2da73f12f3e6b0bbe6aac42f93 /src/check_stmt.cpp
parentc4d2d287fc0eac7348951ce275a1f3d80f25ef3d (diff)
Remove constant from switch for strings
Diffstat (limited to 'src/check_stmt.cpp')
-rw-r--r--src/check_stmt.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp
index 840df6ad9..7d053dee6 100644
--- a/src/check_stmt.cpp
+++ b/src/check_stmt.cpp
@@ -745,7 +745,8 @@ void check_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) {
}
if (a1.mode != Addressing_Invalid &&
- lhs.mode == Addressing_Constant && rhs.mode == Addressing_Constant) {
+ lhs.mode == Addressing_Constant && rhs.mode == Addressing_Constant &&
+ !is_type_string(lhs.type) && !is_type_string(rhs.type)) {
ExactValue start = lhs.value;
ExactValue end = rhs.value;
ExactValue one = exact_value_i64(1);
@@ -950,9 +951,9 @@ void check_type_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) {
return;
}
- Map<bool> seen = {}; // Key: Type *
- map_init(&seen, heap_allocator());
- defer (map_destroy(&seen));
+ PtrSet<Type *> seen = {};
+ ptr_set_init(&seen, heap_allocator());
+ defer (ptr_set_destroy(&seen));
for_array(i, bs->stmts) {
AstNode *stmt = bs->stmts[i];
@@ -995,9 +996,7 @@ void check_type_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) {
GB_PANIC("Unknown type to type switch statement");
}
- HashKey key = hash_type(y.type);
- bool *found = map_get(&seen, key);
- if (found) {
+ if (ptr_set_exists(&seen, y.type)) {
TokenPos pos = cc->token.pos;
gbString expr_str = expr_to_string(y.expr);
error(y.expr,
@@ -1008,7 +1007,7 @@ void check_type_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) {
gb_string_free(expr_str);
break;
}
- map_set(&seen, key, cast(bool)true);
+ ptr_set_add(&seen, y.type);
}
}
@@ -1053,8 +1052,7 @@ void check_type_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) {
for_array(i, variants) {
Type *t = variants[i];
- auto found = map_get(&seen, hash_type(t));
- if (!found) {
+ if (!ptr_set_exists(&seen, t)) {
array_add(&unhandled, t);
}
}