diff options
| author | jason <jkercher43@gmail.com> | 2024-08-07 23:27:45 -0400 |
|---|---|---|
| committer | jason <jkercher43@gmail.com> | 2024-08-07 23:27:45 -0400 |
| commit | 96257985137090e75b52f6b4a9474865f8136cd2 (patch) | |
| tree | 20c8f18e143aa0c9c7a39b6c6d27b59e39a41aa6 /src/check_expr.cpp | |
| parent | c691c7dc68c517068e024df34ac166fd19d2ea0b (diff) | |
| parent | 796feeead9ef2625351ec6745ce7cbc5dde8a911 (diff) | |
merge commit
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 01ff9da5b..4bce42129 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -127,6 +127,8 @@ gb_internal bool complete_soa_type(Checker *checker, Type *t, bool wait_to_finis gb_internal bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y); +gb_internal bool is_exact_value_zero(ExactValue const &v); + enum LoadDirectiveResult { LoadDirective_Success = 0, LoadDirective_Error = 1, @@ -4457,6 +4459,27 @@ gb_internal void convert_to_typed(CheckerContext *c, Operand *operand, Type *tar case Type_Union: + // IMPORTANT NOTE HACK(bill): This is just to allow for comparisons against `0` with the `os.Error` type + // as a kind of transition period + if (!build_context.strict_style && + operand->mode == Addressing_Constant && + target_type->kind == Type_Named && + (c->pkg == nullptr || c->pkg->name != "os") && + target_type->Named.name == "Error") { + Entity *e = target_type->Named.type_name; + if (e->pkg && e->pkg->name == "os") { + if (is_exact_value_zero(operand->value) && + (operand->value.kind == ExactValue_Integer || + operand->value.kind == ExactValue_Float)) { + operand->mode = Addressing_Value; + target_type = t_untyped_nil; + operand->value = empty_exact_value; + update_untyped_expr_value(c, operand->expr, operand->value); + break; + } + } + } + // "fallthrough" if (!is_operand_nil(*operand) && !is_operand_uninit(*operand)) { TEMPORARY_ALLOCATOR_GUARD(); @@ -5135,6 +5158,14 @@ gb_internal Entity *check_selector(CheckerContext *c, Operand *operand, Ast *nod Scope *import_scope = e->ImportName.scope; String entity_name = selector->Ident.token.string; + if (import_scope == nullptr) { + ERROR_BLOCK(); + error(node, "'%.*s' is not imported in this file, '%.*s' is unavailable", LIT(import_name), LIT(entity_name)); + operand->mode = Addressing_Invalid; + operand->expr = node; + return nullptr; + } + check_op_expr = false; entity = scope_lookup_current(import_scope, entity_name); bool allow_builtin = false; |