Skip writeSaveDerivedVar if func ends with return

This commit is contained in:
Nigel Tao committed 2020-02-19 21:10:19 +11:00
1 parent 6a7a4d08e3
commit 21c87ce6b3
3 files changed
+23 -15

No files matched your search

+8
View File
@@ -834,6 +834,14 @@ func (n *Func) Out() *TypeExpr { return n.rhs.AsTypeExpr() }
func (n *Func) Asserts() []*Node { return n.list1 }
func (n *Func) Body() []*Node { return n.list2 }
func (n *Func) BodyEndsWithReturn() bool {
if len(n.list2) == 0 {
return false
}
end := n.list2[len(n.list2)-1]
return (end.kind == KRet) && (end.AsRet().Keyword() == t.IDReturn)
}
func NewFunc(flags Flags, filename string, line uint32, receiverName t.ID, funcName t.ID, in *Struct, out *TypeExpr, asserts []*Node, body []*Node) *Func {
return &Func{
kind: KFunc,