@@ -44,7 +44,7 @@ import (
44
44
//
45
45
// The code below notes where are assumptions are made that only hold true in
46
46
// the case of parameter removal (annotated with 'Assumption:')
47
- func inlineAllCalls (ctx context.Context , snapshot * cache.Snapshot , pkg * cache.Package , pgf * parsego.File , origDecl * ast.FuncDecl , callee * inline.Callee , post func ([]byte ) []byte , opts * inline.Options ) (map [protocol.DocumentURI ][]byte , error ) {
47
+ func inlineAllCalls (ctx context.Context , snapshot * cache.Snapshot , pkg * cache.Package , pgf * parsego.File , origDecl * ast.FuncDecl , callee * inline.Callee , post func ([]byte ) []byte , opts * inline.Options ) (_ map [protocol.DocumentURI ][]byte , inlineErr error ) {
48
48
// Collect references.
49
49
var refs []protocol.Location
50
50
{
@@ -68,6 +68,11 @@ func inlineAllCalls(ctx context.Context, snapshot *cache.Snapshot, pkg *cache.Pa
68
68
var (
69
69
pkgForRef = make (map [protocol.Location ]PackageID )
70
70
pkgs = make (map [PackageID ]* cache.Package )
71
+ // The inliner assumes that input is well-typed, but that is frequently not
72
+ // the case within gopls.
73
+ // Until we're able to harden the inliner, report panics as errors to avoid
74
+ // crashing the server.
75
+ badPkg = false
71
76
)
72
77
{
73
78
needPkgs := make (map [PackageID ]struct {})
@@ -91,9 +96,20 @@ func inlineAllCalls(ctx context.Context, snapshot *cache.Snapshot, pkg *cache.Pa
91
96
92
97
for _ , p := range refPkgs {
93
98
pkgs [p .Metadata ().ID ] = p
99
+ if len (p .ParseErrors ())+ len (p .TypeErrors ()) > 0 {
100
+ badPkg = true
101
+ }
94
102
}
95
103
}
96
104
105
+ if badPkg {
106
+ defer func () {
107
+ if x := recover (); x != nil {
108
+ inlineErr = fmt .Errorf ("inlining failed (%q), likely because inputs were ill-typed" , x )
109
+ }
110
+ }()
111
+ }
112
+
97
113
// Organize calls by top file declaration. Calls within a single file may
98
114
// affect each other, as the inlining edit may affect the surrounding scope
99
115
// or imports Therefore, when inlining subsequent calls in the same
0 commit comments