Check the if condition has boolean type.

This commit is contained in:
Nigel Tao committed 2017-05-13 11:33:31 +10:00
1 parent da9612667e
commit 57598bee41
1 file changed
+6 -2
+6 -2
View File
@@ -91,10 +91,14 @@ func (c *typeChecker) checkStatement(n *a.Node) error {
case a.KIf:
for o := n.If(); o != nil; o = o.ElseIf() {
if err := c.checkExpr(o.Condition()); err != nil {
cond := o.Condition()
if err := c.checkExpr(cond); err != nil {
return err
}
// TODO: check o.Condition() has type bool.
if !cond.MType().Eq(TypeExprBoolean) {
return fmt.Errorf("check: if condition %q, of type %q, does not have a boolean type",
cond.String(c.idMap), cond.MType().String(c.idMap))
}
for _, m := range o.BodyIfTrue() {
if err := c.checkStatement(m); err != nil {
return err