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

go/printer: deletes or inserts AST types into code #33479

Open
stamblerre opened this issue Aug 5, 2019 · 2 comments

Comments

@stamblerre
Copy link
Contributor

commented Aug 5, 2019

Forked from #31291.

We have found that go/printer.Fprint will delete broken code.
An example of code being deleted: https://play.golang.org/p/WKRt74denE0.

We have also found that go/printer.Fprint will insert the string literal BadStmt or BadExpr in broken code that parses into *ast.BadStmts or *ast.BadExprs.
An example of code being rewritten: https://play.golang.org/p/_BBrwbfAtEH.

This was discovered through using the function go/format.Node, which uses go/printer.Fprint. We noticed that format.Source returns an error in such cases, which is the behavior I would expect. I would have expected that format.Source and format.Node would behave the same on the same input.

@mvdan

This comment has been minimized.

Copy link
Member

commented Aug 6, 2019

Does this happen with go/printer too, the underlying package? If so, the issue should probably be retitled.

@stamblerre stamblerre changed the title go/format: format.Node deletes or inserts AST types into code go/printer: deletes or inserts AST types into code Aug 6, 2019

@stamblerre

This comment has been minimized.

Copy link
Contributor Author

commented Aug 6, 2019

Looks like it does, thanks! Updated the issue, title, and playground links to reflect this.

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