Add a nothing built-in literal

This commit is contained in:
Nigel Tao committed 2019-02-03 14:01:19 +11:00
1 parent 49627b46f2
commit d1f1340d47
4 files changed
+12 -5

No files matched your search

+1 -1
View File
@@ -308,7 +308,7 @@ func (q *checker) bcheckStatement(n *a.Node) error {
if q.astFunc.Effect().Coroutine() {
lTyp = typeExprStatus
} else if lTyp == nil {
return fmt.Errorf("TODO: allow returning nothing")
lTyp = typeExprEmptyStruct
}
if _, err := q.bcheckAssignment1(nil, lTyp, t.IDEq, n.Value()); err != nil {
return err
+6 -1
View File
@@ -173,7 +173,7 @@ func (q *checker) tcheckStatement(n *a.Node) error {
if q.astFunc.Effect().Coroutine() {
lTyp = typeExprStatus
} else if lTyp == nil {
return fmt.Errorf("TODO: allow returning nothing")
lTyp = typeExprEmptyStruct
}
value := n.Value()
if err := q.tcheckExpr(value, 0); err != nil {
@@ -391,6 +391,11 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
n.SetMType(typeExprBool)
return nil
case t.IDNothing:
n.SetConstValue(zero)
n.SetMType(typeExprEmptyStruct)
return nil
case t.IDNullptr:
n.SetConstValue(zero)
n.SetMType(typeExprNullptr)