Type and bounds check the "x" in "return x"

This commit is contained in:
Nigel Tao committed 2018-11-24 14:46:52 +11:00
1 parent c84732f3d3
commit 24ace1c144
3 files changed
+32 -11

No files matched your search

+7 -2
View File
@@ -291,10 +291,15 @@ func (q *checker) bcheckStatement(n *a.Node) error {
q.facts = q.facts[:0]
case a.KRet:
// TODO: compare the value to the out type?
n := n.AsRet()
lTyp := q.astFunc.Out()
if q.astFunc.Effect().Optional() {
lTyp = typeExprStatus
} else if lTyp == nil {
return fmt.Errorf("TODO: allow returning nothing")
}
if v := n.Value(); v != nil {
if _, err := q.bcheckExpr(v, 0); err != nil {
if err := q.bcheckAssignment1(nil, lTyp, t.IDEq, v); err != nil {
return err
}
}