提交 5642e0a1 编写于 作者: D Derek Parker

Add nil check when following `Else` in ast

Fixes #137
上级 38f97b40
......@@ -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
})
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册