Check the for-loop condition has boolean type.

This commit is contained in:
Nigel Tao committed 2017-05-13 10:23:21 +10:00
1 parent c3c600627b
commit 87dcd9ed55
2 files changed
+7 -1

No files matched your search

+3
View File
@@ -59,6 +59,9 @@ func TestCheck(t *testing.T) {
b = not true
y = x as i32
for x > 0 {
}
}
`) + "\n"
+4 -1
View File
@@ -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 {