Skip to content
Permalink
Browse files

don't panic on funcs with nil blocks

This can happen with stub function declarations, which are common in
larage codebases.

Fixes #36.
  • Loading branch information...
mvdan committed Mar 6, 2019
1 parent 492ba69 commit a838822c542b6d8e53788cade95937c499712e35
Showing with 9 additions and 1 deletion.
  1. +7 −1 match.go
  2. +2 −0 match_test.go
@@ -510,7 +510,13 @@ func (m *matcher) node(expr, node ast.Node) bool {
return true
}
y, ok := node.(*ast.BlockStmt)
return ok && (m.cases(x.List, y.List) || m.stmts(x.List, y.List))
if !ok {
return false
}
if x == nil || y == nil {
return x == y
}
return m.cases(x.List, y.List) || m.stmts(x.List, y.List)
case *ast.IfStmt:
y, ok := node.(*ast.IfStmt)
if !ok {
@@ -457,6 +457,8 @@ func TestMatch(t *testing.T) {
[]string{"-x", "func $_($x $y) $y { return $x }"},
"func a(i int) int { return i }", 1,
},
{[]string{"-x", "func $x(i int)"}, "func a(i int)", 1},
{[]string{"-x", "func $x(i int) {}"}, "func a(i int)", 0},

// value specs
{[]string{"-x", "$_ int"}, "var a int", 1},

0 comments on commit a838822

Please sign in to comment.
You can’t perform that action at this time.