Skip to content

Commit 90c60a2

Browse files
adonovangopherbot
authored andcommitted
gopls/internal/lsp/source: forgive inliner failures in ill-typed code
The inliner algorithms make widespread assumptions that the input is well-typed, and panic if the input doesn't compile. Previously, gopls would propagate the panic in well-typed code, but convert it to an error plus a bug.Report if the input had type errors. This change removes the bug.Report, since reporting such failures via panic is the intended behavior. (Recovering from another package's panic isn't ideal: what if it fails using log.Fatal, or creates additional goroutines that panic, or corrupts shared state? We happen to know that the inline package does not, but that could change in future.) Also, a test. Fixes golang/go#64558 Change-Id: Id9e7ae1de66e6e50866cef4e907d5596e68cfa23 Reviewed-on: https://go-review.googlesource.com/c/tools/+/548736 Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 6823dc4 commit 90c60a2

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

gopls/internal/lsp/source/inline.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ import (
1111
"fmt"
1212
"go/ast"
1313
"go/types"
14-
"runtime/debug"
1514

1615
"golang.org/x/tools/go/analysis"
1716
"golang.org/x/tools/go/ast/astutil"
1817
"golang.org/x/tools/go/types/typeutil"
1918
"golang.org/x/tools/gopls/internal/file"
2019
"golang.org/x/tools/gopls/internal/lsp/cache"
2120
"golang.org/x/tools/gopls/internal/lsp/protocol"
22-
"golang.org/x/tools/gopls/internal/util/bug"
2321
"golang.org/x/tools/gopls/internal/util/safetoken"
2422
"golang.org/x/tools/internal/diff"
2523
"golang.org/x/tools/internal/event"
@@ -98,8 +96,7 @@ func inlineCall(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, r
9896
if bad(calleePkg) || bad(callerPkg) {
9997
defer func() {
10098
if x := recover(); x != nil {
101-
err = bug.Errorf("inlining failed unexpectedly: %v\nstack: %v",
102-
x, debug.Stack())
99+
err = fmt.Errorf("inlining failed (%q), likely because inputs were ill-typed", x)
103100
}
104101
}()
105102
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Test of an inlining failure due to an ill-typed input program (#64558).
2+
3+
-- go.mod --
4+
module testdata
5+
go 1.18
6+
7+
-- a/a.go --
8+
package a
9+
10+
func _() {
11+
f(1, 2) //@ diag("2", re"too many arguments"), codeactionerr("f", ")", "refactor.inline", re`inlining failed \("args/params mismatch"\), likely because inputs were ill-typed`)
12+
}
13+
14+
func f(int) {}

0 commit comments

Comments
 (0)