fix: foldLeft when type checking, rather than foldRight which is unintuitive
This commit is contained in:
		| @@ -159,7 +159,7 @@ 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.toList.foldRight(arrayTy) { (elem, acc) => |       val elemTy = indices.foldLeft(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) => innerTy | ||||||
| @@ -173,10 +173,10 @@ object typeChecker { | |||||||
|     case Parens(expr) => checkValue(expr, constraint) |     case Parens(expr) => checkValue(expr, constraint) | ||||||
|     case l @ ArrayLiter(elems) => |     case l @ ArrayLiter(elems) => | ||||||
|       KnownType |       KnownType | ||||||
|         .Array(elems.foldRight[SemType](?) { case (elem, acc) => |         .Array(elems.foldLeft[SemType](?) { case (acc, elem) => | ||||||
|           checkValue( |           checkValue( | ||||||
|             elem, |             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) |         .satisfies(constraint, l.pos) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user