diff --git a/src/main/wacc/typeChecker.scala b/src/main/wacc/typeChecker.scala index e58b408..0cfe9d7 100644 --- a/src/main/wacc/typeChecker.scala +++ b/src/main/wacc/typeChecker.scala @@ -99,12 +99,30 @@ object typeChecker { ) case Assign(lhs, rhs) => val lhsTy = checkValue(lhs, Constraint.Unconstrained) - checkValue(rhs, Constraint.Is(lhsTy, s"assignment must have type $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) => - checkValue( - lhs, - Constraint.IsEither(KnownType.Int, KnownType.Char, "read must be int or char") - ) + val lhsTy = checkValue(lhs, Constraint.Unconstrained) + lhsTy match { + case ? => + ctx.error( + Error.SemanticError(lhs.pos, "cannot read into a destination with an unknown type") + ) + case _ => + lhsTy.satisfies( + Constraint.IsEither( + KnownType.Int, + KnownType.Char, + "read must be applied to an int or char" + ), + lhs.pos + ) + } case Free(lhs) => checkValue( lhs, @@ -193,8 +211,9 @@ object typeChecker { elem, Constraint.Is(KnownType.Pair(?, ?), "fst must be applied to a pair") ) match { - case KnownType.Pair(left, _) => left.satisfies(constraint, elem.pos) - case ? => ?.satisfies(constraint, elem.pos) + case what @ KnownType.Pair(left, _) => + left.satisfies(constraint, elem.pos) + case ? => ?.satisfies(constraint, elem.pos) case _ => ctx.error(Error.InternalError(elem.pos, "fst must be applied to a pair")) } // satisfies constraint case Snd(elem) => diff --git a/src/test/wacc/examples.scala b/src/test/wacc/examples.scala index 64c2d51..f62d537 100644 --- a/src/test/wacc/examples.scala +++ b/src/test/wacc/examples.scala @@ -16,7 +16,7 @@ class ParallelExamplesSpec extends AnyFlatSpec with BeforeAndAfterAll with Paral (p.toString, List(200)) } ++ allWaccFiles("wacc-examples/invalid/whack").map { p => - (p.toString, List(0, 100, 200)) + (p.toString, List(100, 200)) } // tests go here @@ -82,7 +82,7 @@ class ParallelExamplesSpec extends AnyFlatSpec with BeforeAndAfterAll with Paral // "wacc-examples/invalid/semanticErr/variables", // "wacc-examples/invalid/semanticErr/while", // invalid (whack) - "wacc-examples/invalid/whack" + // "wacc-examples/invalid/whack" // format: on // format: on ).find(filename.contains).isDefined