Skip to content

Commit

Permalink
cmd/compile/internal/typecheck: remove HasNamedResults check
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Robert Griesemer <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
mdempsky authored and gopherbot committed Sep 12, 2023
1 parent 70fc87e commit 905b58b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
5 changes: 0 additions & 5 deletions src/cmd/compile/internal/ir/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
11 changes: 4 additions & 7 deletions src/cmd/compile/internal/typecheck/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 905b58b

Please sign in to comment.