提交 317057aa 编写于 作者: D Derek Parker

Properly handle infinite for loops when next'ing

上级 1b55fa83
......@@ -191,8 +191,17 @@ func (s *Searcher) parseDefaultBlock(ifRoot ast.Node, parsedFile *ast.File, line
}
if stmt, ok := n.(*ast.ForStmt); ok {
parents = append(parents, stmt.Body)
pos := s.fileset.Position(stmt.Pos())
if stmt.Cond == nil {
nextLine := s.fileset.Position(stmt.Body.List[0].Pos()).Line
if line < nextLine {
lines = []int{nextLine}
found = true
parents = nil
return false
}
}
parents = append(parents, stmt.Body)
parentBlockBeginLine = pos.Line
}
......
......@@ -30,6 +30,7 @@ func TestNextLines(t *testing.T) {
line int
nextlines []int
}{
{5, []int{7}},
{8, []int{9, 10, 13}},
{15, []int{17, 19}},
{25, []int{27}},
......@@ -50,7 +51,7 @@ func TestNextLines(t *testing.T) {
}
if len(lines) != len(c.nextlines) {
fmt.Println(lines)
t.Fatalf("did not get correct number of lines back expected %d got %d for test case %d", len(c.nextlines), len(lines), i+1)
t.Fatalf("did not get correct number of lines back expected %d got %d for test case %d got %#v", len(c.nextlines), len(lines), i+1, lines)
}
for j, l := range lines {
if l != c.nextlines[j] {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册