aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-08-04 10:51:08 +0100
committergingerBill <bill@gingerbill.org>2024-08-04 10:51:08 +0100
commite60951a902976acfef74b863463bb116858366c5 (patch)
tree0bfb984d7a1f788223a230918cd3ab2017fd0752 /src
parent71932628cc3c1957a98e998740b059df9b7dd392 (diff)
Begin converting `os.Errno` to be a `nil`-able type as a transition period
Diffstat (limited to 'src')
-rw-r--r--src/check_expr.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 01ff9da5b..78b88f21a 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,
@@ -4364,6 +4366,25 @@ gb_internal void convert_to_typed(CheckerContext *c, Operand *operand, Type *tar
}
switch (t->kind) {
+ // IMPORTANT NOTE HACK(bill): This is just to allow for comparisons against `0` with the `os.Error` type
+ // as a kind of transition period
+ case Type_Enum:
+ if (operand->mode == Addressing_Constant &&
+ target_type->kind == Type_Named &&
+ 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)) {
+ check_is_expressible(c, operand, t);
+ if (operand->mode == Addressing_Invalid) {
+ return;
+ }
+ update_untyped_expr_value(c, operand->expr, operand->value);
+ }
+ }
+ }
+ break;
+
case Type_Basic:
if (operand->mode == Addressing_Constant) {
check_is_expressible(c, operand, t);