-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
go/printer: can print an invalid return statement depending on position info #32854
Comments
I realise that this could qualify as "abusing" the syntax tree nodes. However, I don't see why |
Conceivably, your updated AST is not a valid one. Perhaps you can verify this using one of the AST library predicates/validators? |
I'd disagree. Even if you print a syntax tree with an empty fileset, the printer should still print a valid program, even if the style ends up looking weird. For example, other similar statements like |
So you are unable to verify whether your generated AST is valid? |
Change https://golang.org/cl/184121 mentions this issue: |
Sorry, I don't know what you mean. The syntax tree is perfectly valid. The position information obtained via the fileset is a bit weird, but still, I don't think that should lead to the printer producing incorrect output and no error. I also don't know what validators you're talking about. You can validate the syntax tree example I gave above, if that helps. |
See golang/go#32854 for the issue reported for upstream.
@mvdan I agree this is a bug. Unfortunately, the |
I understand these edge cases are super rare, primarily because one needs to craft a syntax tree manually. It's impossible for |
@mvdan I can review them but it's not a high priority. The shorter the better, of course :-) |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What did you do?
https://play.golang.org/p/oxljScGL89r
What did you expect to see?
A valid program, like:
What did you see instead?
The
return call()
being printed separately, which means two statements instead of one.To make this more obvious,
gofmt
formats the last piece of code as:I encountered this while writing a program to modify source code. Surprisingly, I ended up with code that wouldn't compile, and figured out it was because the printer wasn't doing the right thing.
I assume this is a small bug that can be fixed, such as not allowing a newline in this case. I'll investigate a bit. /cc @griesemer
The text was updated successfully, but these errors were encountered: