Skip to content

Commit c2567a2

Browse files
committed
go/analysis: handle common nil pointers
Updates golang/go#33727, golang/go#33689 Change-Id: Ie32ac4efc9fe0d7b08fcff3feb44b28d83df942d Reviewed-on: https://go-review.googlesource.com/c/tools/+/190908 Run-TryBot: Rebecca Stambler <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent c4a336e commit c2567a2

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

go/analysis/passes/ctrlflow/ctrlflow.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,11 @@ func run(pass *analysis.Pass) (interface{}, error) {
102102
inspect.Preorder(nodeFilter, func(n ast.Node) {
103103
switch n := n.(type) {
104104
case *ast.FuncDecl:
105-
fn := pass.TypesInfo.Defs[n.Name].(*types.Func)
106-
funcDecls[fn] = &declInfo{decl: n}
107-
decls = append(decls, fn)
108-
105+
// Type information may be incomplete.
106+
if fn, ok := pass.TypesInfo.Defs[n.Name].(*types.Func); ok {
107+
funcDecls[fn] = &declInfo{decl: n}
108+
decls = append(decls, fn)
109+
}
109110
case *ast.FuncLit:
110111
funcLits[n] = new(litInfo)
111112
lits = append(lits, n)

go/analysis/passes/structtag/structtag.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ func run(pass *analysis.Pass) (interface{}, error) {
4040
(*ast.StructType)(nil),
4141
}
4242
inspect.Preorder(nodeFilter, func(n ast.Node) {
43-
styp := pass.TypesInfo.Types[n.(*ast.StructType)].Type.(*types.Struct)
43+
styp, ok := pass.TypesInfo.Types[n.(*ast.StructType)].Type.(*types.Struct)
44+
// Type information may be incomplete.
45+
if !ok {
46+
return
47+
}
4448
var seen namesSeen
4549
for i := 0; i < styp.NumFields(); i++ {
4650
field := styp.Field(i)

internal/lsp/cache/pkg.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (pkg *pkg) GetTypesSizes() types.Sizes {
177177
}
178178

179179
func (pkg *pkg) IsIllTyped() bool {
180-
return pkg.types == nil && pkg.typesInfo == nil
180+
return pkg.types == nil || pkg.typesInfo == nil || pkg.typesSizes == nil
181181
}
182182

183183
func (pkg *pkg) SetDiagnostics(diags []source.Diagnostic) {

internal/lsp/source/analysis.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (act *Action) execOnce(ctx context.Context, fset *token.FileSet) error {
168168
}
169169
act.pass = pass
170170

171-
if act.Pkg.IsIllTyped() && !pass.Analyzer.RunDespiteErrors {
171+
if act.Pkg.IsIllTyped() {
172172
act.err = errors.Errorf("analysis skipped due to errors in package: %v", act.Pkg.GetErrors())
173173
} else {
174174
act.result, act.err = pass.Analyzer.Run(pass)

0 commit comments

Comments
 (0)