aboutsummaryrefslogtreecommitdiff
path: root/types.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-11-24 16:13:23 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-11-24 16:13:23 -0500
commit0e10313d64f54dd587ebbcd5f413bd999333c911 (patch)
tree16a07c4b01467d59807611b23f91f9eb125959e2 /types.c
parent6ecf6a272446af04f3affd354520d21127a5b952 (diff)
Switch `NaN` to be identical to the null value
Diffstat (limited to 'types.c')
-rw-r--r--types.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/types.c b/types.c
index 5c26d07a..b57ff7ba 100644
--- a/types.c
+++ b/types.c
@@ -207,6 +207,11 @@ static PUREFUNC INLINE double type_max_magnitude(type_t *t)
PUREFUNC precision_cmp_e compare_precision(type_t *a, type_t *b)
{
+ if (a->tag == OptionalType && Match(a, OptionalType)->type->tag == NumType)
+ a = Match(a, OptionalType)->type;
+ if (b->tag == OptionalType && Match(b, OptionalType)->type->tag == NumType)
+ b = Match(b, OptionalType)->type;
+
if (is_int_type(a) && b->tag == NumType)
return NUM_PRECISION_LESS;
else if (a->tag == NumType && is_int_type(b))
@@ -338,6 +343,10 @@ PUREFUNC bool can_promote(type_t *actual, type_t *needed)
if (actual->tag == PointerType && can_promote(Match(actual, PointerType)->pointed, needed))
return true;
+ // Optional num -> num
+ if (needed->tag == NumType && actual->tag == OptionalType && Match(actual, OptionalType)->type->tag == NumType)
+ return can_promote(Match(actual, OptionalType)->type, needed);
+
// Optional promotion:
if (needed->tag == OptionalType && can_promote(actual, Match(needed, OptionalType)->type))
return true;