aboutsummaryrefslogtreecommitdiff
path: root/src/typecheck.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-05 02:13:24 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-05 02:13:24 -0400
commit486f2153e84f2b82ddffc601de75289cddb9c942 (patch)
tree6852412958366d52d9b5b40b5748434f44079ef8 /src/typecheck.c
parent81316e0d9704834a0a648cf84401b968933b7581 (diff)
Misc fixes
Diffstat (limited to 'src/typecheck.c')
-rw-r--r--src/typecheck.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/typecheck.c b/src/typecheck.c
index 1bef98c8..7b86ec63 100644
--- a/src/typecheck.c
+++ b/src/typecheck.c
@@ -1055,6 +1055,11 @@ type_t *get_type(env_t *env, ast_t *ast)
type_t *lhs_t = get_type(env, binop.lhs);
type_t *rhs_t = get_type(env, binop.rhs);
+ if (binop.lhs->tag == Int && (is_int_type(rhs_t) || rhs_t->tag == ByteType))
+ return rhs_t;
+ else if (binop.rhs->tag == Int && (is_int_type(lhs_t) || lhs_t->tag == ByteType))
+ return lhs_t;
+
// `opt? or (x == y)` / `(x == y) or opt?` is a boolean conditional:
if ((lhs_t->tag == OptionalType && rhs_t->tag == BoolType)
|| (lhs_t->tag == BoolType && rhs_t->tag == OptionalType)) {
@@ -1096,6 +1101,11 @@ type_t *get_type(env_t *env, ast_t *ast)
type_t *lhs_t = get_type(env, binop.lhs);
type_t *rhs_t = get_type(env, binop.rhs);
+ if (binop.lhs->tag == Int && (is_int_type(rhs_t) || rhs_t->tag == ByteType))
+ return rhs_t;
+ else if (binop.rhs->tag == Int && (is_int_type(lhs_t) || lhs_t->tag == ByteType))
+ return lhs_t;
+
// `and` between optionals/bools is a boolean expression like `if opt? and opt?:` or `if x > 0 and opt?:`
if ((lhs_t->tag == OptionalType || lhs_t->tag == BoolType)
&& (rhs_t->tag == OptionalType || rhs_t->tag == BoolType)) {
@@ -1125,6 +1135,11 @@ type_t *get_type(env_t *env, ast_t *ast)
type_t *lhs_t = get_type(env, binop.lhs);
type_t *rhs_t = get_type(env, binop.rhs);
+ if (binop.lhs->tag == Int && (is_int_type(rhs_t) || rhs_t->tag == ByteType))
+ return rhs_t;
+ else if (binop.rhs->tag == Int && (is_int_type(lhs_t) || lhs_t->tag == ByteType))
+ return lhs_t;
+
// `xor` between optionals/bools is a boolean expression like `if opt? xor opt?:` or `if x > 0 xor opt?:`
if ((lhs_t->tag == OptionalType || lhs_t->tag == BoolType)
&& (rhs_t->tag == OptionalType || rhs_t->tag == BoolType)) {