mvdan/gogrep

$*_ for function return values

quasilyte opened this issue · 1 comments

Given example.go:

package example

func f0()            { return }
func f1() int        { return 1 }
func f2() (int, int) { return 1, 2 }

If we run gogrep like this:

gogrep -x 'func $_() $*_ { $*_ }' example.go

We only get 2 results:

hello.go:4:1: func f1() int { return 1; }
hello.go:5:1: func f2() (int, int) { return 1, 2; }

This could be an issue, since $*_ is described as something that can be used to match optional pattern pieces. Right now, if we want to describe an arbitrary function result, two patterns are needed:

func $_() $*_ { $*_ } // 1-N results
func $_() { $*_ } // 0 results
mvdan commented

Yeah, I've been bitten by this too. We probably need a bit of extra glue code to make this work. Will take a look.