Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Support for $*_ inside function params #48

Open
quasilyte opened this issue Dec 24, 2019 · 1 comment
Open

Support for $*_ inside function params #48

quasilyte opened this issue Dec 24, 2019 · 1 comment

Comments

@quasilyte
Copy link
Contributor

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?

@mvdan
Copy link
Owner

mvdan commented Dec 24, 2019

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants