diff --git a/src/main/wacc/typeChecker.scala b/src/main/wacc/typeChecker.scala index c0ed0c1..2105ecb 100644 --- a/src/main/wacc/typeChecker.scala +++ b/src/main/wacc/typeChecker.scala @@ -95,28 +95,27 @@ object typeChecker { ) case Assign(lhs, rhs) => val lhsTy = checkValue(lhs, Constraint.Unconstrained) - checkValue(rhs, Constraint.Is(lhsTy, s"assignment must have type $lhsTy")) match { - case ? => + (lhsTy, checkValue(rhs, Constraint.Is(lhsTy, s"assignment must have type $lhsTy"))) match { + case (?, ?) => ctx.error( Error.SemanticError(lhs.pos, "assignment with both sides of unknown type is illegal") ) case _ => () } - case Read(lhs) => - val lhsTy = checkValue(lhs, Constraint.Unconstrained) - lhsTy match { + case Read(dest) => + checkValue(dest, Constraint.Unconstrained) match { case ? => ctx.error( - Error.SemanticError(lhs.pos, "cannot read into a destination with an unknown type") + Error.SemanticError(dest.pos, "cannot read into a destination with an unknown type") ) - case _ => - lhsTy.satisfies( + case destTy => + destTy.satisfies( Constraint.IsEither( KnownType.Int, KnownType.Char, "read must be applied to an int or char" ), - lhs.pos + dest.pos ) } case Free(lhs) =>