Skip to content

Commit ee69ea2

Browse files
mateusz834gopherbot
authored andcommitted
go/analysis/analysistest: avoid nil panic from an invalid token.Pos
See failures in CL 638395 Change-Id: I03ea2ab77fd71707eb9fd6c2dd53ab553f5d8563 GitHub-Last-Rev: 39e217e GitHub-Pull-Request: #549 Reviewed-on: https://go-review.googlesource.com/c/tools/+/638415 Auto-Submit: Robert Griesemer <[email protected]> Commit-Queue: Alan Donovan <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Alan Donovan <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 1743d1a commit ee69ea2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

go/analysis/analysistest/analysistest.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,20 @@ func RunWithSuggestedFixes(t Testing, dir string, a *analysis.Analyzer, patterns
191191
act.Analyzer.Name, start, end)
192192
continue
193193
}
194-
file, endfile := act.Package.Fset.File(start), act.Package.Fset.File(end)
195-
if file == nil || endfile == nil || file != endfile {
194+
file := act.Package.Fset.File(start)
195+
if file == nil {
196+
t.Errorf("diagnostic for analysis %v contains Suggested Fix with malformed start position %v", act.Analyzer.Name, start)
197+
continue
198+
}
199+
endFile := act.Package.Fset.File(end)
200+
if endFile == nil {
201+
t.Errorf("diagnostic for analysis %v contains Suggested Fix with malformed end position %v", act.Analyzer.Name, end)
202+
continue
203+
}
204+
if file != endFile {
196205
t.Errorf(
197206
"diagnostic for analysis %v contains Suggested Fix with malformed spanning files %v and %v",
198-
act.Analyzer.Name, file.Name(), endfile.Name())
207+
act.Analyzer.Name, file.Name(), endFile.Name())
199208
continue
200209
}
201210
if _, ok := fileContents[file]; !ok {

0 commit comments

Comments
 (0)