diff options
| author | Ginger Bill <bill@gingerbill.org> | 2016-11-20 01:34:43 +0000 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2016-11-20 01:34:43 +0000 |
| commit | 24347ced45aabd3ce4f4a261b8140a976cadff2e (patch) | |
| tree | 32ba1cd9ec5ce7503dd0a86ad8e417cc73324cc1 /src/checker/types.cpp | |
| parent | 24ca1065214f51cfbeb9c0eff98002c7d33139a2 (diff) | |
Support `any` in `match type`
Diffstat (limited to 'src/checker/types.cpp')
| -rw-r--r-- | src/checker/types.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/checker/types.cpp b/src/checker/types.cpp index 92111f186..0fbcd84bb 100644 --- a/src/checker/types.cpp +++ b/src/checker/types.cpp @@ -396,7 +396,14 @@ gb_global Type *t_context = NULL; gb_global Type *t_context_ptr = NULL; - +Type *get_enum_base_type(Type *t) { + Type *bt = base_type(t); + if (bt->kind == Type_Record && bt->Record.kind == TypeRecord_Enum) { + GB_ASSERT(bt->Record.enum_base != NULL); + return bt->Record.enum_base; + } + return t; +} b32 is_type_named(Type *t) { if (t->kind == Type_Basic) { @@ -457,7 +464,7 @@ b32 is_type_untyped(Type *t) { return false; } b32 is_type_ordered(Type *t) { - t = base_type(t); + t = base_type(get_enum_base_type(t)); if (t->kind == Type_Basic) { return (t->Basic.flags & BasicFlag_Ordered) != 0; } @@ -581,14 +588,6 @@ b32 is_type_raw_union(Type *t) { return (t->kind == Type_Record && t->Record.kind == TypeRecord_RawUnion); } -Type *get_enum_base_type(Type *t) { - Type *bt = base_type(t); - if (is_type_enum(bt)) { - return bt->Record.enum_base; - } - return t; -} - b32 is_type_any(Type *t) { t = base_type(t); return (t->kind == Type_Basic && t->Basic.kind == Basic_any); @@ -626,7 +625,7 @@ b32 type_has_nil(Type *t) { b32 is_type_comparable(Type *t) { - t = base_type(t); + t = base_type(get_enum_base_type(t)); switch (t->kind) { case Type_Basic: return t->kind != Basic_UntypedNil; |