diff --git a/lang/check/check_test.go b/lang/check/check_test.go index cb9abaca..07ef46c8 100644 --- a/lang/check/check_test.go +++ b/lang/check/check_test.go @@ -59,6 +59,9 @@ func TestCheck(t *testing.T) { b = not true y = x as i32 + + for x > 0 { + } } `) + "\n" diff --git a/lang/check/type.go b/lang/check/type.go index add50d0e..a162731d 100644 --- a/lang/check/type.go +++ b/lang/check/type.go @@ -89,7 +89,10 @@ func (c *typeChecker) checkStatement(n *a.Node) error { if err := c.checkExpr(cond); err != nil { return err } - // TODO: check cond has type bool. + if !cond.MType().Eq(TypeExprBoolean) { + return fmt.Errorf("check: for-loop condition %q, of type %q, does not have a boolean type", + cond.String(c.idMap), cond.MType().String(c.idMap)) + } } for _, m := range o.Body() { if err := c.checkStatement(m); err != nil {