fix: foldLeft when type checking, rather than foldRight which is unintuitive

This commit is contained in:
Gleb Koval 2025-02-07 14:16:50 +00:00
parent 68e4762b37
commit 319fa606d9
Signed by: cyclane
GPG Key ID: 15E168A8B332382C

View File

@ -159,7 +159,7 @@ object typeChecker {
ctx.typeOf(id).satisfies(constraint, id.pos)
case ArrayElem(id, indices) =>
val arrayTy = ctx.typeOf(id)
val elemTy = indices.toList.foldRight(arrayTy) { (elem, acc) =>
val elemTy = indices.foldLeft(arrayTy) { (acc, elem) =>
checkValue(elem, Constraint.Is(KnownType.Int, "array index must be an int"))
acc match {
case KnownType.Array(innerTy) => innerTy
@ -173,10 +173,10 @@ object typeChecker {
case Parens(expr) => checkValue(expr, constraint)
case l @ ArrayLiter(elems) =>
KnownType
.Array(elems.foldRight[SemType](?) { case (elem, acc) =>
.Array(elems.foldLeft[SemType](?) { case (acc, elem) =>
checkValue(
elem,
Constraint.IsSymmetricCompatible(acc, "array elements must have the same type")
Constraint.IsSymmetricCompatible(acc, s"array elements must have the same type")
)
})
.satisfies(constraint, l.pos)