fix: return proper type in non-array index error (instead of ?
)
This commit is contained in:
parent
88ddca2b98
commit
ba1b7d67c7
@ -159,17 +159,18 @@ object typeChecker {
|
|||||||
ctx.typeOf(id).satisfies(constraint, id.pos)
|
ctx.typeOf(id).satisfies(constraint, id.pos)
|
||||||
case ArrayElem(id, indices) =>
|
case ArrayElem(id, indices) =>
|
||||||
val arrayTy = ctx.typeOf(id)
|
val arrayTy = ctx.typeOf(id)
|
||||||
val elemTy = indices.foldLeft(arrayTy) { (acc, elem) =>
|
val elemTy = indices.foldLeftM(arrayTy) { (acc, elem) =>
|
||||||
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) => innerTy
|
case KnownType.Array(innerTy) => Some(innerTy)
|
||||||
case _ =>
|
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")
|
||||||
)
|
)
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elemTy.satisfies(constraint, id.pos)
|
elemTy.getOrElse(?).satisfies(constraint, id.pos)
|
||||||
case Parens(expr) => checkValue(expr, constraint)
|
case Parens(expr) => checkValue(expr, constraint)
|
||||||
case l @ ArrayLiter(elems) =>
|
case l @ ArrayLiter(elems) =>
|
||||||
KnownType
|
KnownType
|
||||||
|
Loading…
x
Reference in New Issue
Block a user