aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-08-17 15:24:44 +0100
committergingerBill <bill@gingerbill.org>2018-08-17 15:24:44 +0100
commit1d0ac72e4a6851effe0a9310a26974675c177cc1 (patch)
treef274bd0323db255a81bdfd1ce6212d32f89ea555
parentb216e44870b1883cf3fb71994eb94f642fea43a1 (diff)
Disable non-comparison operations for enum (use `bit_set` for flags)
-rw-r--r--examples/demo/demo.odin7
-rw-r--r--src/check_decl.cpp2
-rw-r--r--src/types.cpp22
3 files changed, 17 insertions, 14 deletions
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin
index 9a592bc43..bab7caf0c 100644
--- a/examples/demo/demo.odin
+++ b/examples/demo/demo.odin
@@ -614,6 +614,11 @@ using_enum :: proc() {
f2 := C;
fmt.println(f0, f1, f2);
fmt.println(len(Foo));
+
+ // Non-comparsion operations are not allowed with enum
+ // You must convert to an integer if you want to do this
+ // x := f0 + f1;
+ y := int(f0) + int(f1);
}
explicit_procedure_overloading :: proc() {
@@ -772,6 +777,6 @@ main :: proc() {
complete_switch();
cstring_example();
deprecated_attribute();
- }
bit_set_type();
+ }
}
diff --git a/src/check_decl.cpp b/src/check_decl.cpp
index 9d6c4cc65..8569ee437 100644
--- a/src/check_decl.cpp
+++ b/src/check_decl.cpp
@@ -253,7 +253,7 @@ void check_type_decl(CheckerContext *ctx, Entity *e, Ast *type_expr, Type *def)
if (decl->is_using) {
// NOTE(bill): Must be an enum declaration
if (te->kind == Ast_EnumType) {
- Scope *parent = ctx->scope->parent;
+ Scope *parent = e->scope;
if (parent->flags&ScopeFlag_File) {
// NOTE(bill): Use package scope
parent = parent->parent;
diff --git a/src/types.cpp b/src/types.cpp
index 695187f05..92dd9d37e 100644
--- a/src/types.cpp
+++ b/src/types.cpp
@@ -659,42 +659,40 @@ bool is_type_named_alias(Type *t) {
}
bool is_type_boolean(Type *t) {
- t = core_type(t);
+ // t = core_type(t);
+ t = base_type(t);
if (t->kind == Type_Basic) {
return (t->Basic.flags & BasicFlag_Boolean) != 0;
}
return false;
}
bool is_type_integer(Type *t) {
- t = core_type(t);
+ // t = core_type(t);
+ t = base_type(t);
if (t->kind == Type_Basic) {
return (t->Basic.flags & BasicFlag_Integer) != 0;
}
return false;
}
bool is_type_unsigned(Type *t) {
- t = core_type(t);
+ t = base_type(t);
+ // t = core_type(t);
if (t->kind == Type_Basic) {
return (t->Basic.flags & BasicFlag_Unsigned) != 0;
}
return false;
}
bool is_type_rune(Type *t) {
- t = core_type(t);
+ // t = core_type(t);
+ t = base_type(t);
if (t->kind == Type_Basic) {
return (t->Basic.flags & BasicFlag_Rune) != 0;
}
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);
+ // t = core_type(t);
+ t = base_type(t);
if (t->kind == Type_Basic) {
return (t->Basic.flags & BasicFlag_Numeric) != 0;
}