fix: make int binary operators and char binary operators errors consistent

This commit is contained in:
Gleb Koval 2025-02-07 18:02:31 +00:00
parent 8a7b37e05f
commit 4d25d7a730
Signed by: cyclane
GPG Key ID: 15E168A8B332382C

View File

@ -246,18 +246,17 @@ object typeChecker {
) )
KnownType.Bool.satisfies(constraint, op.pos) KnownType.Bool.satisfies(constraint, op.pos)
case op: (Less | LessEq | Greater | GreaterEq) => case op: (Less | LessEq | Greater | GreaterEq) =>
val xTy = checkValue( val xConstraint = Constraint.IsEither(
op.x,
Constraint.IsEither(
KnownType.Int, KnownType.Int,
KnownType.Char, KnownType.Char,
s"${op.name} operator must be applied to an int or char" s"${op.name} operator must be applied to an int or char"
) )
) val yConstraint = checkValue(op.x, xConstraint) match {
checkValue( case ? => xConstraint
op.y, case xTy =>
Constraint.Is(xTy, s"${op.name} operator must be applied to values of the same type") 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) KnownType.Bool.satisfies(constraint, op.pos)
case op: (And | Or) => case op: (And | Or) =>
val operand = Constraint.Is(KnownType.Bool, s"${op.name} operator must be applied to a bool") val operand = Constraint.Is(KnownType.Bool, s"${op.name} operator must be applied to a bool")