fix: check both sides are unknown for assign error message
This commit is contained in:
parent
3d2725be8d
commit
8a7b37e05f
@ -95,28 +95,27 @@ object typeChecker {
|
|||||||
)
|
)
|
||||||
case Assign(lhs, rhs) =>
|
case Assign(lhs, rhs) =>
|
||||||
val lhsTy = checkValue(lhs, Constraint.Unconstrained)
|
val lhsTy = checkValue(lhs, Constraint.Unconstrained)
|
||||||
checkValue(rhs, Constraint.Is(lhsTy, s"assignment must have type $lhsTy")) match {
|
(lhsTy, checkValue(rhs, Constraint.Is(lhsTy, s"assignment must have type $lhsTy"))) match {
|
||||||
case ? =>
|
case (?, ?) =>
|
||||||
ctx.error(
|
ctx.error(
|
||||||
Error.SemanticError(lhs.pos, "assignment with both sides of unknown type is illegal")
|
Error.SemanticError(lhs.pos, "assignment with both sides of unknown type is illegal")
|
||||||
)
|
)
|
||||||
case _ => ()
|
case _ => ()
|
||||||
}
|
}
|
||||||
case Read(lhs) =>
|
case Read(dest) =>
|
||||||
val lhsTy = checkValue(lhs, Constraint.Unconstrained)
|
checkValue(dest, Constraint.Unconstrained) match {
|
||||||
lhsTy match {
|
|
||||||
case ? =>
|
case ? =>
|
||||||
ctx.error(
|
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 _ =>
|
case destTy =>
|
||||||
lhsTy.satisfies(
|
destTy.satisfies(
|
||||||
Constraint.IsEither(
|
Constraint.IsEither(
|
||||||
KnownType.Int,
|
KnownType.Int,
|
||||||
KnownType.Char,
|
KnownType.Char,
|
||||||
"read must be applied to an int or char"
|
"read must be applied to an int or char"
|
||||||
),
|
),
|
||||||
lhs.pos
|
dest.pos
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
case Free(lhs) =>
|
case Free(lhs) =>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user