From cfef667a899339a0fd5b79214d581db6ede10748 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 11 Sep 2024 23:13:41 -0400 Subject: Fix optional integer promotion --- compile.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index f5ed809d..8da5eba4 100644 --- a/compile.c +++ b/compile.c @@ -44,6 +44,7 @@ CORD promote_to_optional(type_t *t, CORD code) return code; } } + static bool promote(env_t *env, CORD *code, type_t *actual, type_t *needed) { if (type_eq(actual, needed)) @@ -52,6 +53,12 @@ static bool promote(env_t *env, CORD *code, type_t *actual, type_t *needed) if (!can_promote(actual, needed)) return false; + // Optional promotion: + if (needed->tag == OptionalType && type_eq(actual, Match(needed, OptionalType)->type)) { + *code = promote_to_optional(actual, *code); + return true; + } + if (actual->tag == IntType && needed->tag == BigIntType) { *code = CORD_all("I(", *code, ")"); return true; @@ -81,12 +88,6 @@ static bool promote(env_t *env, CORD *code, type_t *actual, type_t *needed) return promote(env, code, Match(actual, PointerType)->pointed, needed); } - // Optional promotion: - if (needed->tag == OptionalType && type_eq(actual, Match(needed, OptionalType)->type)) { - *code = promote_to_optional(actual, *code); - return true; - } - // Stack ref promotion: if (actual->tag == PointerType && needed->tag == PointerType) return true; -- cgit v1.2.3