Skip to content

Commit ee2e6da

Browse files
committed
go/analysis/analysistest: avoid nil panic from an invalid token.Pos
See failures in CL 638395
1 parent ebeac1b commit ee2e6da

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

go/analysis/analysistest/analysistest.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,16 @@ func RunWithSuggestedFixes(t Testing, dir string, a *analysis.Analyzer, patterns
193193
}
194194
file, endfile := act.Package.Fset.File(start), act.Package.Fset.File(end)
195195
if file == nil || endfile == nil || file != endfile {
196+
fileName := func(p token.Pos) string {
197+
file := act.Package.Fset.File(start)
198+
if file != nil {
199+
return file.Name()
200+
}
201+
return fmt.Sprintf("<invalid file pos: %v>", p)
202+
}
196203
t.Errorf(
197204
"diagnostic for analysis %v contains Suggested Fix with malformed spanning files %v and %v",
198-
act.Analyzer.Name, file.Name(), endfile.Name())
205+
act.Analyzer.Name, fileName(start), fileName(end))
199206
continue
200207
}
201208
if _, ok := fileContents[file]; !ok {

0 commit comments

Comments
 (0)