-
Notifications
You must be signed in to change notification settings - Fork 2
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
When positions doesn't matter #3
Comments
This is a good point. It could also be beneficial if you'll share your use case where copied position info makes things worse, just for the context. Thank you. |
CC @cristaloleg |
I do not suggest that we break the current implementation, just that we maybe ad (in some way) this one. |
My use case is that I'm trying to create a Stub/Mock creator and therefore want to copy arguments and results of function calls. When I've built the syntax tree, I format it with func// Func2 mock
(m *Mocked) Func2(str string, str2 string) {
return m.Func2Func(str, str2)
} Which is technically correct go code. But obviusly not what I want. When I strip any positions the result is // Func2 mock
func (m *Mocked) Func2(str string, str2 string) {
return m.Func2Func(str, str2)
} |
Got it. cp := astcopy.BinaryExpr(orig)
cp.OpPos = orig.OpPos Or, if only cp := astcopy.BinaryExpr(orig)
cp.X.Pos = orig.X.Pos Another way is to provide a set of functions that do not copy pos info, so backwards-compatibility is preserved. Although the exported function set will increase in almost 2 times. Or we can do it in a same way how |
ping @cristaloleg |
I'm voting for the:
I think we can break compatibility for know and see how many users will ask about an ability to copy pos automatically. Objections? |
Ooops. Wanted to ping you :) |
I have since long moved on from this problem (Used string templates instead) 🙂 . But I do at least have no objection to this. |
I've come across a problem where I want to copy everything except the position.
To solve this problem I cloned
astcopy.go
and made changes to all functions.For example, this is how the UnaryExpr is now copied:
Is this something you would like to incorporate into this repo. Otherwise I will clone this repo and make an alternative version of it.
The text was updated successfully, but these errors were encountered: