From 21432ba96efc2622f12b2939a0e5d9c2baa0d2c2 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 17 Feb 2018 18:34:14 +0000 Subject: [PATCH] Clean up range code for switch --- src/check_stmt.cpp | 4 ++-- src/types.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 7d053dee6..a8208b7dd 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -744,9 +744,9 @@ void check_switch_stmt(Checker *c, AstNode *node, u32 mod_flags) { } } - if (a1.mode != Addressing_Invalid && + if (a1.mode != Addressing_Invalid && b1.mode != Addressing_Invalid && lhs.mode == Addressing_Constant && rhs.mode == Addressing_Constant && - !is_type_string(lhs.type) && !is_type_string(rhs.type)) { + is_type_number(lhs.type) && is_type_number(rhs.type)) { ExactValue start = lhs.value; ExactValue end = rhs.value; ExactValue one = exact_value_i64(1); diff --git a/src/types.cpp b/src/types.cpp index 09b91ee34..1f9724578 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -666,6 +666,13 @@ bool is_type_rune(Type *t) { } return false; } +bool is_type_number(Type *t) { + t = core_type(t); + if (t->kind == Type_Basic) { + return (t->Basic.flags & BasicFlag_Numeric) != 0; + } + return false; +} bool is_type_numeric(Type *t) { t = core_type(t); if (t->kind == Type_Basic) {