Skip to content

Commit 9a04136

Browse files
committed
gopls/internal/golang/stubmethods: refine crash into bug report
This CL refine an as-yet unreproducible crash into a bug report. It seems clear that the code intended to check that sig != nil, yet instead checked that sig.Results != nil. With that said, I don't think it's possible to have a return statement without an enclosing signature. For now, turn this into a bug report. For golang/go#70666 Change-Id: I79031d437d643f6d70360e3abde86166176647b3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/633375 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 01e0b05 commit 9a04136

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

gopls/internal/golang/stubmethods/stubmethods.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import (
1313
"go/ast"
1414
"go/token"
1515
"go/types"
16-
"golang.org/x/tools/internal/typesinternal"
1716
"strings"
1817

18+
"golang.org/x/tools/internal/typesinternal"
19+
20+
"golang.org/x/tools/gopls/internal/util/bug"
1921
"golang.org/x/tools/gopls/internal/util/typesutil"
2022
)
2123

@@ -282,8 +284,9 @@ func fromReturnStmt(fset *token.FileSet, info *types.Info, pos token.Pos, path [
282284
}
283285

284286
sig := typesutil.EnclosingSignature(path, info)
285-
if sig.Results() == nil {
286-
return nil, fmt.Errorf("could not find the enclosing function of the return statement")
287+
if sig == nil {
288+
// golang/go#70666: this bug may be reached in practice.
289+
return nil, bug.Errorf("could not find the enclosing function of the return statement")
287290
}
288291
rets := sig.Results()
289292
// The return operands and function results must match.

0 commit comments

Comments
 (0)