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
Open

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

stamblerre opened this issue Aug 5, 2019 · 2 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@stamblerre
Copy link
Contributor

stamblerre 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.

@agnivade agnivade added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 6, 2019
@agnivade agnivade added this to the Go1.14 milestone Aug 6, 2019
@mvdan
Copy link
Member

mvdan 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
Copy link
Contributor Author

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

@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants