diff --git a/src/main/wacc/typeChecker.scala b/src/main/wacc/typeChecker.scala index 2105ecb..80eda2e 100644 --- a/src/main/wacc/typeChecker.scala +++ b/src/main/wacc/typeChecker.scala @@ -246,18 +246,17 @@ object typeChecker { ) KnownType.Bool.satisfies(constraint, op.pos) case op: (Less | LessEq | Greater | GreaterEq) => - val xTy = checkValue( - op.x, - Constraint.IsEither( - KnownType.Int, - KnownType.Char, - s"${op.name} operator must be applied to an int or char" - ) - ) - checkValue( - op.y, - Constraint.Is(xTy, s"${op.name} operator must be applied to values of the same type") + val xConstraint = Constraint.IsEither( + KnownType.Int, + KnownType.Char, + s"${op.name} operator must be applied to an int or char" ) + val yConstraint = checkValue(op.x, xConstraint) match { + case ? => xConstraint + case xTy => + Constraint.Is(xTy, s"${op.name} operator must be applied to values of the same type") + } + checkValue(op.y, yConstraint) KnownType.Bool.satisfies(constraint, op.pos) case op: (And | Or) => val operand = Constraint.Is(KnownType.Bool, s"${op.name} operator must be applied to a bool")