fix: check both sides are unknown for assign error message

This commit is contained in:
Gleb Koval 2025-02-07 17:32:24 +00:00
parent 3d2725be8d
commit 8a7b37e05f
Signed by: cyclane
GPG Key ID: 15E168A8B332382C

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) =>