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 23 additions and 13 deletions
Showing only changes of commit 8a7b37e05f - Show all commits

View File

@@ -95,28 +95,27 @@ object typeChecker {
)
case Assign(lhs, rhs) =>
val lhsTy = checkValue(lhs, Constraint.Unconstrained)
checkValue(rhs, Constraint.Is(lhsTy, s"assignment must have type $lhsTy")) match {
case ? =>
(lhsTy, checkValue(rhs, Constraint.Is(lhsTy, s"assignment must have type $lhsTy"))) match {
case (?, ?) =>
ctx.error(
Error.SemanticError(lhs.pos, "assignment with both sides of unknown type is illegal")
)
case _ => ()
}
case Read(lhs) =>
val lhsTy = checkValue(lhs, Constraint.Unconstrained)
lhsTy match {
case Read(dest) =>
checkValue(dest, Constraint.Unconstrained) match {
case ? =>
ctx.error(
Error.SemanticError(lhs.pos, "cannot read into a destination with an unknown type")
Error.SemanticError(dest.pos, "cannot read into a destination with an unknown type")
)
case _ =>
lhsTy.satisfies(
case destTy =>
destTy.satisfies(
Constraint.IsEither(
KnownType.Int,
KnownType.Char,
"read must be applied to an int or char"
),
lhs.pos
dest.pos
)
}
case Free(lhs) =>