1
0
mirror of https://github.com/golang/go synced 2024-11-18 17:54:57 -07:00

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 <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Matthew Dempsky 2023-09-11 17:23:55 -07:00 committed by Gopher Robot
parent 70fc87ee24
commit 905b58b537
2 changed files with 4 additions and 12 deletions

View File

@ -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.
//

View File

@ -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
}