Add nil check when following Else in ast

Fixes #137
This commit is contained in:
Derek Parker
2015-06-21 11:48:22 -05:00
parent 38f97b4023
commit 5642e0a106

View File

@ -120,22 +120,24 @@ func (s *Searcher) NextLines(fname string, line int) (lines []int, err error) {
x = stmt
continue
}
pos := s.fileset.Position(x.Else.Pos())
ast.Inspect(x, func(n ast.Node) bool {
if found {
panic(Done("done"))
}
if n == nil {
return false
}
p := s.fileset.Position(n.Pos())
if pos.Line < p.Line {
lines = append(lines, p.Line)
found = true
return false
}
return true
})
if x.Else != nil {
pos := s.fileset.Position(x.Else.Pos())
ast.Inspect(x, func(n ast.Node) bool {
if found {
panic(Done("done"))
}
if n == nil {
return false
}
p := s.fileset.Position(n.Pos())
if pos.Line < p.Line {
lines = append(lines, p.Line)
found = true
return false
}
return true
})
}
}
}