feat: reduce appearances of unknown-type, catch illegal function calls #19

Merged
gk1623 merged 6 commits from error-message-improvements into master 2025-02-07 18:14:37 +00:00
2 changed files with 33 additions and 24 deletions
Showing only changes of commit 4d25d7a730 - Show all commits

View File

@@ -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")