Skip to content

go/printer: printed output cannot be parsed if comments are retained #6554

@adonovan

Description

@adonovan
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions