diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2024-08-04 15:53:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-04 15:53:18 +0100 |
| commit | f427f040fd83f5db411396bd4d4eae6f39c26de7 (patch) | |
| tree | 0ee1feef26570f195a8d0d00d0266edc028dbfec /src/check_expr.cpp | |
| parent | 71932628cc3c1957a98e998740b059df9b7dd392 (diff) | |
| parent | c078b2dd1be617e6687a3a5ffc919a45bbabb5bf (diff) | |
Merge pull request #4020 from odin-lang/bill/os-errno
`os.Error` to replace `os.Errno`
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 01ff9da5b..b291cbe70 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(); |