diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-12-21 15:13:26 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-12-21 15:13:26 -0500 |
| commit | 325b367a1342826fe7174ce45cfab92091d4dbb5 (patch) | |
| tree | 921b306025e495f71f008f9f9a4b1291ce2cdcb3 /typecheck.c | |
| parent | 478ddad9aaf837005f5401126f8872c0e3058bba (diff) | |
Support logical binary operators on optionals (promote to booleans)
Diffstat (limited to 'typecheck.c')
| -rw-r--r-- | typecheck.c | 9 |
1 files changed, 9 insertions, 0 deletions
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); |
