mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-21 00:47:28 +01:00
Make the return value mandatory; add ok
This commit is contained in:
1 parent
24ace1c144
commit
762b320b5e
11 files changed
+45
-50
No files matched your search
@@ -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
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user