Make the return value mandatory; add ok

This commit is contained in:
Nigel Tao committed 2018-11-24 15:09:28 +11:00
1 parent 24ace1c144
commit 762b320b5e
11 files changed
+45 -50

No files matched your search

+2 -4
View File
@@ -298,10 +298,8 @@ func (q *checker) bcheckStatement(n *a.Node) error {
} else if lTyp == nil {
return fmt.Errorf("TODO: allow returning nothing")
}
if v := n.Value(); v != nil {
if err := q.bcheckAssignment1(nil, lTyp, t.IDEq, v); err != nil {
return err
}
if err := q.bcheckAssignment1(nil, lTyp, t.IDEq, n.Value()); err != nil {
return err
}
case a.KVar:
+13 -9
View File
@@ -191,15 +191,14 @@ func (q *checker) tcheckStatement(n *a.Node) error {
} else if lTyp == nil {
return fmt.Errorf("TODO: allow returning nothing")
}
if value := n.Value(); value != nil {
if err := q.tcheckExpr(value, 0); err != nil {
return err
}
rTyp := value.MType()
if !(rTyp.IsIdeal() && lTyp.IsNumType()) && !lTyp.EqIgnoringRefinements(rTyp) {
return fmt.Errorf("check: cannot return %q (of type %q) as type %q",
value.Str(q.tm), rTyp.Str(q.tm), lTyp.Str(q.tm))
}
value := n.Value()
if err := q.tcheckExpr(value, 0); err != nil {
return err
}
rTyp := value.MType()
if !(rTyp.IsIdeal() && lTyp.IsNumType()) && !lTyp.EqIgnoringRefinements(rTyp) {
return fmt.Errorf("check: cannot return %q (of type %q) as type %q",
value.Str(q.tm), rTyp.Str(q.tm), lTyp.Str(q.tm))
}
case a.KVar:
@@ -431,6 +430,11 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
n.SetConstValue(zero)
n.SetMType(typeExprNullptr)
return nil
case t.IDOk:
n.SetConstValue(zero)
n.SetMType(typeExprStatus)
return nil
}
case t.IDOpenParen, t.IDTry: