feat: improve semantic errors #15

Merged
gk1623 merged 5 commits from improve-semantic-errors into master 2025-02-07 15:07:36 +00:00
2 changed files with 4 additions and 4 deletions
Showing only changes of commit 319fa606d9 - Show all commits

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)