fix: make free error message more clear

This commit is contained in:
Gleb Koval 2025-02-07 17:19:16 +00:00
parent e87e61b152
commit b5e72660b7
Signed by: cyclane
GPG Key ID: 15E168A8B332382C

View File

@ -125,7 +125,7 @@ object typeChecker {
Constraint.IsEither( Constraint.IsEither(
KnownType.Array(?), KnownType.Array(?),
KnownType.Pair(?, ?), KnownType.Pair(?, ?),
"free must be an array or pair" "free must be applied to an array or pair"
) )
) )
case Return(expr) => case Return(expr) =>
@ -163,6 +163,7 @@ object typeChecker {
checkValue(elem, Constraint.Is(KnownType.Int, "array index must be an int")) checkValue(elem, Constraint.Is(KnownType.Int, "array index must be an int"))
acc match { acc match {
case KnownType.Array(innerTy) => Some(innerTy) case KnownType.Array(innerTy) => Some(innerTy)
case ? => Some(?)
case nonArrayTy => case nonArrayTy =>
ctx.error( ctx.error(
Error.TypeMismatch(elem.pos, KnownType.Array(?), acc, "cannot index into a non-array") Error.TypeMismatch(elem.pos, KnownType.Array(?), acc, "cannot index into a non-array")