diff --git a/src/check_expr.cpp b/src/check_expr.cpp index ea9936235..855be62e1 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -486,6 +486,12 @@ i64 check_distance_between_types(CheckerContext *c, Operand *operand, Type *type } } + if (is_type_enum(dst) && are_types_identical(dst->Enum.base_type, operand->type)) { + if (c->in_enum_type) { + return 3; + } + } + #if 0 if (are_types_identical(dst, src) && (!is_type_named(dst) || !is_type_named(src))) { return 1; diff --git a/src/check_type.cpp b/src/check_type.cpp index e4bd3dd2b..7b0ff8488 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -1931,6 +1931,7 @@ bool check_type_internal(CheckerContext *ctx, AstNode *e, Type **type, Type *nam bool ips = ctx->in_polymorphic_specialization; defer (ctx->in_polymorphic_specialization = ips); ctx->in_polymorphic_specialization = false; + ctx->in_enum_type = true; *type = alloc_type_enum(); set_base_type(named_type, *type); diff --git a/src/checker.cpp b/src/checker.cpp index 73130732e..52e054743 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -549,9 +549,6 @@ void init_universal_scope(void) { add_global_constant(str_lit("false"), t_untyped_bool, exact_value_bool(false)); add_global_entity(alloc_entity_nil(str_lit("nil"), t_untyped_nil)); - // add_global_entity(alloc_entity_library_name(universal_scope, - // make_token_ident(str_lit("__llvm_core")), t_invalid, - // str_lit(""), str_lit("__llvm_core"))); // TODO(bill): Set through flags in the compiler add_global_string_constant(str_lit("ODIN_VENDOR"), bc->ODIN_VENDOR); diff --git a/src/checker.hpp b/src/checker.hpp index 212331fa3..a4987dd0b 100644 --- a/src/checker.hpp +++ b/src/checker.hpp @@ -343,6 +343,7 @@ struct CheckerContext { CheckerTypePath *type_path; isize type_level; // TODO(bill): Actually handle correctly + bool in_enum_type; bool collect_delayed_decls; bool allow_polymorphic_types; bool no_polymorphic_errors; diff --git a/src/parser.cpp b/src/parser.cpp index a11fadef4..780ab1574 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1030,7 +1030,6 @@ AstNode *ast_attribute(AstFile *f, Token token, Token open, Token close, Arraycurr_token; if (f->curr_token_index+1 < f->tokens.count) { f->curr_token = f->tokens[++f->curr_token_index]; return true; diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index c89b1ca6d..da0e6517d 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -82,49 +82,49 @@ TOKEN_KIND(Token__ComparisonEnd, ""), \ TOKEN_KIND(Token__OperatorEnd, ""), \ \ TOKEN_KIND(Token__KeywordBegin, ""), \ - TOKEN_KIND(Token_import, "import"), \ - TOKEN_KIND(Token_export, "export"), \ - TOKEN_KIND(Token_foreign, "foreign"), \ - TOKEN_KIND(Token_package, "package"), \ - TOKEN_KIND(Token_type, "type"), \ - TOKEN_KIND(Token_when, "when"), \ - TOKEN_KIND(Token_if, "if"), \ - TOKEN_KIND(Token_else, "else"), \ - TOKEN_KIND(Token_for, "for"), \ - TOKEN_KIND(Token_switch, "switch"), \ - TOKEN_KIND(Token_in, "in"), \ - TOKEN_KIND(Token_do, "do"), \ - TOKEN_KIND(Token_case, "case"), \ - TOKEN_KIND(Token_break, "break"), \ - TOKEN_KIND(Token_continue, "continue"), \ - TOKEN_KIND(Token_fallthrough, "fallthrough"), \ - TOKEN_KIND(Token_defer, "defer"), \ - TOKEN_KIND(Token_return, "return"), \ - TOKEN_KIND(Token_proc, "proc"), \ - TOKEN_KIND(Token_macro, "macro"), \ - TOKEN_KIND(Token_struct, "struct"), \ - TOKEN_KIND(Token_union, "union"), \ - TOKEN_KIND(Token_enum, "enum"), \ - TOKEN_KIND(Token_bit_field, "bit_field"), \ - TOKEN_KIND(Token_map, "map"), \ - TOKEN_KIND(Token_static, "static"), \ - TOKEN_KIND(Token_dynamic, "dynamic"), \ - TOKEN_KIND(Token_auto_cast, "auto_cast"), \ - TOKEN_KIND(Token_cast, "cast"), \ - TOKEN_KIND(Token_transmute, "transmute"), \ - TOKEN_KIND(Token_distinct, "distinct"), \ - TOKEN_KIND(Token_using, "using"), \ - TOKEN_KIND(Token_inline, "inline"), \ - TOKEN_KIND(Token_no_inline, "no_inline"), \ - TOKEN_KIND(Token_context, "context"), \ - TOKEN_KIND(Token_size_of, "size_of"), \ - TOKEN_KIND(Token_align_of, "align_of"), \ - TOKEN_KIND(Token_offset_of, "offset_of"), \ - TOKEN_KIND(Token_type_of, "type_of"), \ - TOKEN_KIND(Token_const, "const"), \ - TOKEN_KIND(Token_asm, "asm"), \ - TOKEN_KIND(Token_yield, "yield"), \ - TOKEN_KIND(Token_await, "await"), \ + TOKEN_KIND(Token_import, "import"), \ + TOKEN_KIND(Token_export, "export"), \ + TOKEN_KIND(Token_foreign, "foreign"), \ + TOKEN_KIND(Token_package, "package"), \ + TOKEN_KIND(Token_type, "type"), \ + TOKEN_KIND(Token_when, "when"), \ + TOKEN_KIND(Token_if, "if"), \ + TOKEN_KIND(Token_else, "else"), \ + TOKEN_KIND(Token_for, "for"), \ + TOKEN_KIND(Token_switch, "switch"), \ + TOKEN_KIND(Token_in, "in"), \ + TOKEN_KIND(Token_do, "do"), \ + TOKEN_KIND(Token_case, "case"), \ + TOKEN_KIND(Token_break, "break"), \ + TOKEN_KIND(Token_continue, "continue"), \ + TOKEN_KIND(Token_fallthrough, "fallthrough"), \ + TOKEN_KIND(Token_defer, "defer"), \ + TOKEN_KIND(Token_return, "return"), \ + TOKEN_KIND(Token_proc, "proc"), \ + TOKEN_KIND(Token_macro, "macro"), \ + TOKEN_KIND(Token_struct, "struct"), \ + TOKEN_KIND(Token_union, "union"), \ + TOKEN_KIND(Token_enum, "enum"), \ + TOKEN_KIND(Token_bit_field, "bit_field"), \ + TOKEN_KIND(Token_map, "map"), \ + TOKEN_KIND(Token_static, "static"), \ + TOKEN_KIND(Token_dynamic, "dynamic"), \ + TOKEN_KIND(Token_auto_cast, "auto_cast"), \ + TOKEN_KIND(Token_cast, "cast"), \ + TOKEN_KIND(Token_transmute, "transmute"), \ + TOKEN_KIND(Token_distinct, "distinct"), \ + TOKEN_KIND(Token_using, "using"), \ + TOKEN_KIND(Token_inline, "inline"), \ + TOKEN_KIND(Token_no_inline, "no_inline"), \ + TOKEN_KIND(Token_context, "context"), \ + TOKEN_KIND(Token_size_of, "size_of"), \ + TOKEN_KIND(Token_align_of, "align_of"), \ + TOKEN_KIND(Token_offset_of, "offset_of"), \ + TOKEN_KIND(Token_type_of, "type_of"), \ + TOKEN_KIND(Token_const, "const"), \ + TOKEN_KIND(Token_asm, "asm"), \ + TOKEN_KIND(Token_yield, "yield"), \ + TOKEN_KIND(Token_await, "await"), \ TOKEN_KIND(Token__KeywordEnd, ""), \ TOKEN_KIND(Token_Count, "")