From 290b8dbf51f46980355c91df59e8ca4a36ff0f48 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Thu, 29 Jan 2026 16:44:25 +0000 Subject: [PATCH] [mypyc] ircheck: Check that integer comparisons have compatible signs --- mypyc/analysis/ircheck.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mypyc/analysis/ircheck.py b/mypyc/analysis/ircheck.py index fc09e1aa926e7..efa3cf046f2c4 100644 --- a/mypyc/analysis/ircheck.py +++ b/mypyc/analysis/ircheck.py @@ -417,12 +417,20 @@ def visit_int_op(self, op: IntOp) -> None: or (op_str not in ("<<", ">>") and left.size != right.size) ) ): - self.fail(op, f"Operand types have incompatible signs: {op.lhs.type}, {op.rhs.type}") + self.fail(op, f"Operand types have incompatible signs: {left}, {right}") def visit_comparison_op(self, op: ComparisonOp) -> None: self.check_compatibility(op, op.lhs.type, op.rhs.type) self.expect_non_float(op, op.lhs) self.expect_non_float(op, op.rhs) + left = op.lhs.type + right = op.rhs.type + if ( + isinstance(left, RPrimitive) + and isinstance(right, RPrimitive) + and left.is_signed != right.is_signed + ): + self.fail(op, f"Operand types have incompatible signs: {left}, {right}") def visit_float_op(self, op: FloatOp) -> None: self.expect_float(op, op.lhs)