Skip to content

Commit ff9f623

Browse files
committed
Avoid panic for empty BlockStmt
Some blocks might be empty, example https://github.com/golang/sys/blob/master/unix/gccgo.go#L16 To avoid this from panicking we just ignore those nodes.
1 parent dc83f80 commit ff9f623

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
language: go
33

44
go:
5+
- "1.13"
56
- "1.12"
67
- "1.11"
78

go.mod

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
module github.com/bombsimon/wsl
22

33
require (
4-
github.com/bombsimon/perl-go v0.0.0-20190628170512-70ac6776c140
5-
github.com/davecgh/go-spew v1.1.1
6-
github.com/stretchr/objx v0.2.0 // indirect
7-
github.com/stretchr/testify v1.3.0
4+
github.com/davecgh/go-spew v1.1.1 // indirect
5+
github.com/kr/pretty v0.1.0 // indirect
6+
github.com/stretchr/testify v1.4.0
7+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
8+
gopkg.in/yaml.v2 v2.2.3 // indirect
89
)
10+
11+
go 1.11

go.sum

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1-
github.com/bombsimon/perl-go v0.0.0-20190628170512-70ac6776c140 h1:83DD05xUTjfW/jBdXHpDRGVKeepCOO42zjvQzTzarmo=
2-
github.com/bombsimon/perl-go v0.0.0-20190628170512-70ac6776c140/go.mod h1:8TRAZWMsxZ4bv+fnpkw1aJAxk7DjIl/HcOA/M5AZGwo=
31
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
42
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
53
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
64
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
6+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
7+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
8+
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
9+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
710
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
811
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
912
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
10-
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
11-
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
12-
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
13+
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
14+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
15+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
16+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
17+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
18+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
19+
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
20+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
21+
gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
22+
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

wsl.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ func (p *processor) process(filename string, data []byte) {
8282
// parseBlockBody will parse any kind of block statements such as switch cases
8383
// and if statements. A list of Result is returned.
8484
func (p *processor) parseBlockBody(block *ast.BlockStmt) {
85+
// Nothing to do if there's no value.
86+
if reflect.ValueOf(block).IsNil() {
87+
return
88+
}
89+
8590
// Start by finding leading and trailing whitespaces.
8691
p.findLeadingAndTrailingWhitespaces(block, nil)
8792

wsl_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ func TestGenericHandling(t *testing.T) {
4242
// }
4343
}`),
4444
},
45+
{
46+
description: "do not panic on empty blocks",
47+
code: []byte(`package main
48+
49+
func x(r string) (x uintptr)`),
50+
},
4551
}
4652

4753
for _, tc := range cases {

0 commit comments

Comments
 (0)