From 325b367a1342826fe7174ce45cfab92091d4dbb5 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 21 Dec 2024 15:13:26 -0500 Subject: Support logical binary operators on optionals (promote to booleans) --- typecheck.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'typecheck.c') diff --git a/typecheck.c b/typecheck.c index ea3cd3af..7f655606 100644 --- a/typecheck.c +++ b/typecheck.c @@ -1027,6 +1027,9 @@ type_t *get_type(env_t *env, ast_t *ast) case BINOP_AND: { if (lhs_t->tag == BoolType && rhs_t->tag == BoolType) { return lhs_t; + } else if ((lhs_t->tag == BoolType && rhs_t->tag == OptionalType) || + (lhs_t->tag == OptionalType && rhs_t->tag == BoolType)) { + return Type(BoolType); } else if (lhs_t->tag == BoolType && (rhs_t->tag == AbortType || rhs_t->tag == ReturnType)) { return lhs_t; } else if (rhs_t->tag == AbortType || rhs_t->tag == ReturnType) { @@ -1048,6 +1051,9 @@ type_t *get_type(env_t *env, ast_t *ast) case BINOP_OR: { if (lhs_t->tag == BoolType && rhs_t->tag == BoolType) { return lhs_t; + } else if ((lhs_t->tag == BoolType && rhs_t->tag == OptionalType) || + (lhs_t->tag == OptionalType && rhs_t->tag == BoolType)) { + return Type(BoolType); } else if (lhs_t->tag == BoolType && (rhs_t->tag == AbortType || rhs_t->tag == ReturnType)) { return lhs_t; } else if ((is_int_type(lhs_t) && is_int_type(rhs_t)) @@ -1075,6 +1081,9 @@ type_t *get_type(env_t *env, ast_t *ast) case BINOP_XOR: { if (lhs_t->tag == BoolType && rhs_t->tag == BoolType) { return lhs_t; + } else if ((lhs_t->tag == BoolType && rhs_t->tag == OptionalType) || + (lhs_t->tag == OptionalType && rhs_t->tag == BoolType)) { + return Type(BoolType); } else if ((is_int_type(lhs_t) && is_int_type(rhs_t)) || (lhs_t->tag == ByteType && rhs_t->tag == ByteType)) { return get_math_type(env, ast, lhs_t, rhs_t); -- cgit v1.2.3