Skip to content

Commit 290b8db

Browse files
committed
[mypyc] ircheck: Check that integer comparisons have compatible signs
1 parent 0f6fd82 commit 290b8db

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

mypyc/analysis/ircheck.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,20 @@ def visit_int_op(self, op: IntOp) -> None:
417417
or (op_str not in ("<<", ">>") and left.size != right.size)
418418
)
419419
):
420-
self.fail(op, f"Operand types have incompatible signs: {op.lhs.type}, {op.rhs.type}")
420+
self.fail(op, f"Operand types have incompatible signs: {left}, {right}")
421421

422422
def visit_comparison_op(self, op: ComparisonOp) -> None:
423423
self.check_compatibility(op, op.lhs.type, op.rhs.type)
424424
self.expect_non_float(op, op.lhs)
425425
self.expect_non_float(op, op.rhs)
426+
left = op.lhs.type
427+
right = op.rhs.type
428+
if (
429+
isinstance(left, RPrimitive)
430+
and isinstance(right, RPrimitive)
431+
and left.is_signed != right.is_signed
432+
):
433+
self.fail(op, f"Operand types have incompatible signs: {left}, {right}")
426434

427435
def visit_float_op(self, op: FloatOp) -> None:
428436
self.expect_float(op, op.lhs)

0 commit comments

Comments
 (0)