Skip to content

Commit

Permalink
go/analysis/analysistest: avoid nil panic from an invalid token.Pos
Browse files Browse the repository at this point in the history
See failures in CL 638395
  • Loading branch information
mateusz834 committed Dec 22, 2024
1 parent ebeac1b commit ee2e6da
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion go/analysis/analysistest/analysistest.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,16 @@ func RunWithSuggestedFixes(t Testing, dir string, a *analysis.Analyzer, patterns
}
file, endfile := act.Package.Fset.File(start), act.Package.Fset.File(end)
if file == nil || endfile == nil || file != endfile {
fileName := func(p token.Pos) string {
file := act.Package.Fset.File(start)
if file != nil {
return file.Name()
}
return fmt.Sprintf("<invalid file pos: %v>", p)
}
t.Errorf(
"diagnostic for analysis %v contains Suggested Fix with malformed spanning files %v and %v",
act.Analyzer.Name, file.Name(), endfile.Name())
act.Analyzer.Name, fileName(start), fileName(end))
continue
}
if _, ok := fileContents[file]; !ok {
Expand Down

0 comments on commit ee2e6da

Please sign in to comment.