Skip to content

Commit

Permalink
gopls/internal/golang/stubmethods: refine crash into bug report
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
findleyr committed Dec 3, 2024
1 parent 01e0b05 commit 9a04136
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gopls/internal/golang/stubmethods/stubmethods.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
"go/ast"
"go/token"
"go/types"
"golang.org/x/tools/internal/typesinternal"
"strings"

"golang.org/x/tools/internal/typesinternal"

"golang.org/x/tools/gopls/internal/util/bug"
"golang.org/x/tools/gopls/internal/util/typesutil"
)

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

sig := typesutil.EnclosingSignature(path, info)
if sig.Results() == nil {
return nil, fmt.Errorf("could not find the enclosing function of the return statement")
if sig == nil {
// golang/go#70666: this bug may be reached in practice.
return nil, bug.Errorf("could not find the enclosing function of the return statement")
}
rets := sig.Results()
// The return operands and function results must match.
Expand Down

0 comments on commit 9a04136

Please sign in to comment.