diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-05-03 14:28:19 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-05-03 14:28:19 -0400 |
| commit | 0df984c4b2ec7cdc683b452ffea068c220470405 (patch) | |
| tree | 1f81ce8b2028c4e8ad789bab65b0b7f03c02b62b /src/compile.c | |
| parent | 51a5bf63a2a9dd73e5b20b0b9aab2f87c6400eb0 (diff) | |
Bugfix for promotions in comparisons
Diffstat (limited to 'src/compile.c')
| -rw-r--r-- | src/compile.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/src/compile.c b/src/compile.c index 0eab15bc..8494766a 100644 --- a/src/compile.c +++ b/src/compile.c @@ -2805,26 +2805,16 @@ CORD compile(env_t *env, ast_t *ast) type_t *lhs_t = get_type(env, binop.lhs); type_t *rhs_t = get_type(env, binop.rhs); type_t *operand_t; - if (is_numeric_type(lhs_t) && binop.rhs->tag == Int) { + if (binop.lhs->tag == Int && is_numeric_type(rhs_t)) { + operand_t = rhs_t; + } else if (binop.rhs->tag == Int && is_numeric_type(lhs_t)) { + operand_t = lhs_t; + } else if (can_compile_to_type(env, binop.rhs, lhs_t)) { operand_t = lhs_t; - } else if (is_numeric_type(rhs_t) && binop.lhs->tag == Int) { + } else if (can_compile_to_type(env, binop.lhs, rhs_t)) { operand_t = rhs_t; } else { - switch (compare_precision(lhs_t, rhs_t)) { - case NUM_PRECISION_LESS: operand_t = rhs_t; break; - case NUM_PRECISION_MORE: operand_t = lhs_t; break; - case NUM_PRECISION_EQUAL: operand_t = lhs_t; break; - default: { - if (can_compile_to_type(env, binop.rhs, lhs_t)) { - operand_t = lhs_t; - } else if (can_compile_to_type(env, binop.lhs, rhs_t)) { - operand_t = rhs_t; - } else { - code_err(ast, "I can't do comparisons between ", type_to_str(lhs_t), " and ", type_to_str(rhs_t)); - } - break; - } - } + code_err(ast, "I can't do comparisons between ", type_to_str(lhs_t), " and ", type_to_str(rhs_t)); } CORD lhs, rhs; |
