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: printed output cannot be parsed if comments are retained #6554

Open
adonovan opened this Issue Oct 9, 2013 · 4 comments

Comments

Projects
None yet
3 participants
@adonovan
Copy link

adonovan commented Oct 9, 2013

This program:
  http://play.golang.org/p/f3VrIs2Z70
parses a syntactically well-formed Go program, inserts an additional statement, then
prints it out again.  The result cannot be parsed because a newline was inserted in an
inappropriate place to accommodate a comment.  Here's the output:

package P

func f() {
    print("12"
    /*hi*/)
    g(0, 1)
}

Note that the length of the literal "12" is critical: if a shorter expression
is used, the /*hi*/ comment, which is retains its association with its original byte
offset, will not be inserted at that point.
@griesemer

This comment has been minimized.

Copy link
Contributor

griesemer commented Oct 9, 2013

Comment 1:

The current go/printer has its limitations, and one of them is that it relies crucially
on correct position information in the input AST. Arguably the input to the printer is
incorrect.

Status changed to Thinking.

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Nov 27, 2013

Comment 2:

Labels changed: added go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Dec 4, 2013

Comment 3:

Labels changed: added release-none, removed go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Dec 4, 2013

Comment 4:

Labels changed: added repo-main.

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.