Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/cmd/eg: matches should be limited to value expressions #14728

Open
mdempsky opened this issue Mar 9, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@mdempsky
Copy link
Member

commented Mar 9, 2016

$ cat a.go
package a
func before(x *int) int { return *x }
func after(x *int) int { return 42 }

$ cat b.go
package b
func x(p **int) {}

$ eg -t a.go b.go
=== b.go (1 matches)
package b

func x(p 42)    {}

The problem appears to be that in the type expression **int, the subexpression *int has type *int, so eg is deciding that it's a candidate match for the original expression. However, *int is a type expression, so it doesn't make sense to replace it with a value expression like 42.

I think eg needs to make use of go/types.TypeAndValue's IsValue method.

/cc @alandonovan

@mdempsky mdempsky added this to the Unreleased milestone Mar 9, 2016

@mdempsky

This comment has been minimized.

Copy link
Member Author

commented Apr 14, 2017

The problem is that eg uses go/types.(*Info).TypeOf (in (*Transformer).matchWildcard) to find the type of a candidate expression to match against, but TypeOf doesn't distinguish type vs value expressions.

Easiest fix seems to be to duplicate TypeOf into eg and augment it with the extra type vs value logic. I'm curious if this functionality is useful to other go/types consumers though.

@gopherbot

This comment has been minimized.

Copy link

commented Apr 14, 2017

CL https://golang.org/cl/40772 mentions this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.