mvdan / gogrep

Search for Go code using syntax trees
BSD 3-Clause "New" or "Revised" License
476 stars 16 forks source link

Panic when gogrep is used with "-a 'package/lib/type'" and "-x '$x, _ := $a.Method()'" #40

Closed DmitriyMV closed 5 years ago

DmitriyMV commented 5 years ago

Continuation from slack thread, here is the panic:

panic: resolveType TODO: *ast.BinaryExpr

goroutine 1 [running]:
main.(*matcher).resolveType(0xc0000cab60, 0xc0059c0d70, 0x139f940, 0xc000075bc0, 0xc004f99ef0, 0xc0000cab01)
        /Users/dmatrenichev/go/src/mvdan.cc/gogrep/match.go:634 +0x555
main.(*matcher).attrApplies(0xc0000cab60, 0x139e680, 0xc006230580, 0x1302c60, 0xc00000acc0, 0x100813b)
        /Users/dmatrenichev/go/src/mvdan.cc/gogrep/match.go:194 +0x6e5
main.(*matcher).cmdAttr(0xc0000cab60, 0x1344535, 0x1, 0x7ffeefbff978, 0x3d, 0x1302c60, 0xc00000acc0, 0xc001c8ff40, 0x1, 0x1, ...)
        /Users/dmatrenichev/go/src/mvdan.cc/gogrep/match.go:155 +0xff
main.(*matcher).cmdAttr-fm(0x1344535, 0x1, 0x7ffeefbff978, 0x3d, 0x1302c60, 0xc00000acc0, 0xc001c8ff40, 0x1, 0x1, 0xc006223080, ...)
        /Users/dmatrenichev/go/src/mvdan.cc/gogrep/match.go:78 +0x79
main.(*matcher).submatches(0xc0000cab60, 0xc0000a2120, 0x1, 0x2, 0xc001c8ff40, 0x1, 0x1, 0x1, 0x1, 0xc001c8ff40)
        /Users/dmatrenichev/go/src/mvdan.cc/gogrep/match.go:89 +0x136
main.(*matcher).submatches(0xc0000cab60, 0xc0000a20f0, 0x2, 0x3, 0xc005badee0, 0x1, 0x1, 0x1f, 0x1f, 0xc005badee0)
        /Users/dmatrenichev/go/src/mvdan.cc/gogrep/match.go:89 +0x1a3
main.(*matcher).submatches(0xc0000cab60, 0xc0000a20c0, 0x3, 0x4, 0xc003bbc000, 0x1f, 0x1f, 0x1636000, 0x0, 0x0)
        /Users/dmatrenichev/go/src/mvdan.cc/gogrep/match.go:89 +0x1a3
main.(*matcher).matches(0xc0000cab60, 0xc0000a20c0, 0x3, 0x4, 0xc0019e1600, 0x1f, 0x1f, 0x0, 0x0, 0x0)
        /Users/dmatrenichev/go/src/mvdan.cc/gogrep/match.go:24 +0x1d9
main.(*matcher).fromArgs(0xc0000cab60, 0x1344515, 0x1, 0xc00000e0f0, 0x1, 0x1, 0x12e8a60, 0xc000037dd8)
        /Users/dmatrenichev/go/src/mvdan.cc/gogrep/main.go:155 +0x20f
main.main()
        /Users/dmatrenichev/go/src/mvdan.cc/gogrep/main.go:63 +0xf9
mvdan commented 5 years ago

Thanks for the issue! gogrep will get some attention soon, so I'll take a look at this one.

mvdan commented 5 years ago

@DmitriyMV sorry, I can't reproduce this right now with a command that makes sense. Could you please provide what command you used?

I can reproduce the panic with a query like gogrep -x 'append($x, $*_)' -a 'type(foo + bar)' strings, but that doesn't make much sense. It's impossible to have foo + bar as a type.

mvdan commented 5 years ago

I've fixed that kind of incorrect type expression panic. If you still encounter panics, please provide an example and I'll be happy to investigate.