Support for $*_ inside function params
quasilyte opened this issue · 1 comments
It seems impossible right now to match "a function declaration that has a parameter of type T".
This attempts to do that doesn't work:
$ gogrep -x 'func $_($*_, $_ T, $*_) { $*_ }' .
cannot parse expr: 1: expected '(', found gogrep_0
This pattern is parsed successfully, but it doesn't behave as expected:
$ gogrep -x 'func $_($*_ $_, $_ T, $*_ $_) { $*_ }' .
I also tried these variations:
func $_($*_ $*_, $_ int, $*_ $*_) { $*_ }
func $_($_ $*_, $_ int, $_ $*_) { $*_ }
Maybe there should be a special case for $*_
inside parameter lists?
Yep, this is because we transform the source into something like func gogrep_0(gogrep_1 , gogrep_2 uint, gogrep_3 ) gogrep_4 { gogrep_5 }
, and that results in an internal error when trying to re-parse this as a declaration: 1:61: expected type, found ')'
.
In this particular case, the solution would probably be to make dollar expressions include a type when they are part of a field list. However, that's easier said than done; the source transformation of course happens before any parsing.