From 5642e0a106f8a8a035835fce9275ab402316be08 Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Sun, 21 Jun 2015 11:48:22 -0500 Subject: [PATCH] Add nil check when following `Else` in ast Fixes #137 --- source/source.go | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/source/source.go b/source/source.go index f2fc71de..0120d387 100644 --- a/source/source.go +++ b/source/source.go @@ -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 + }) + } } } -- GitLab