From: Matthew Dempsky Date: Tue, 12 Sep 2023 00:23:55 +0000 (-0700) Subject: cmd/compile/internal/typecheck: remove HasNamedResults check X-Git-Tag: go1.22rc1~892 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=905b58b5377e8f542590a46a3c90146ab45a6c96;p=gostls13.git cmd/compile/internal/typecheck: remove HasNamedResults check types2 has already checked for us that bare returns are valid, so no need to duplicate the effort in typecheck. Change-Id: I13b2387173966ba44058fbc841327896e04184e2 Reviewed-on: https://go-review.googlesource.com/c/go/+/527515 Auto-Submit: Matthew Dempsky Reviewed-by: Robert Griesemer LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/compile/internal/ir/node.go b/src/cmd/compile/internal/ir/node.go index f3d1f21eeb..300084aea6 100644 --- a/src/cmd/compile/internal/ir/node.go +++ b/src/cmd/compile/internal/ir/node.go @@ -482,11 +482,6 @@ func IsMethod(n Node) bool { return n.Type().Recv() != nil } -func HasNamedResults(fn *Func) bool { - typ := fn.Type() - return typ.NumResults() > 0 && types.OrigSym(typ.Result(0).Sym) != nil -} - // HasUniquePos reports whether n has a unique position that can be // used for reporting error messages. // diff --git a/src/cmd/compile/internal/typecheck/stmt.go b/src/cmd/compile/internal/typecheck/stmt.go index 93a147c335..9bb3f79392 100644 --- a/src/cmd/compile/internal/typecheck/stmt.go +++ b/src/cmd/compile/internal/typecheck/stmt.go @@ -423,17 +423,14 @@ func tcRange(n *ir.RangeStmt) { // tcReturn typechecks an ORETURN node. func tcReturn(n *ir.ReturnStmt) ir.Node { - typecheckargs(n) if ir.CurFunc == nil { - base.Errorf("return outside function") - n.SetType(nil) - return n + base.FatalfAt(n.Pos(), "return outside function") } - if ir.HasNamedResults(ir.CurFunc) && len(n.Results) == 0 { - return n + typecheckargs(n) + if len(n.Results) != 0 { + typecheckaste(ir.ORETURN, nil, false, ir.CurFunc.Type().Results(), n.Results, func() string { return "return argument" }) } - typecheckaste(ir.ORETURN, nil, false, ir.CurFunc.Type().Results(), n.Results, func() string { return "return argument" }) return n }