mirror of https://github.com/golang/go.git
go/printer: if comment gets formatted away, don't squash
We were dropping the preceding whitespace. Fixes #53059 Change-Id: Ide0d6a76c463a7481ec4883a8568f7f7b5e87e9f Reviewed-on: https://go-review.googlesource.com/c/go/+/408394 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
757f3c802a
commit
557244cef7
|
|
@ -747,6 +747,18 @@ func (p *printer) intersperseComments(next token.Position, tok token.Token) (wro
|
|||
// a top-level doc comment.
|
||||
list = formatDocComment(list)
|
||||
changed = true
|
||||
|
||||
if len(p.comment.List) > 0 && len(list) == 0 {
|
||||
// The doc comment was removed entirely.
|
||||
// Keep preceding whitespace.
|
||||
p.writeCommentPrefix(p.posFor(p.comment.Pos()), next, last, tok)
|
||||
// Change print state to continue at next.
|
||||
p.pos = next
|
||||
p.last = next
|
||||
// There can't be any more comments.
|
||||
p.nextComment()
|
||||
return p.writeCommentSuffix(false)
|
||||
}
|
||||
}
|
||||
for _, c := range list {
|
||||
p.writeCommentPrefix(p.posFor(c.Pos()), next, last, tok)
|
||||
|
|
|
|||
|
|
@ -767,4 +767,8 @@ var _ = []T{ // lone comments
|
|||
// in composite lit
|
||||
}
|
||||
|
||||
func _() {}
|
||||
|
||||
func _() {}
|
||||
|
||||
/* This comment is the last entry in this file. It must be printed and should be followed by a newline */
|
||||
|
|
|
|||
|
|
@ -765,4 +765,9 @@ var _ = []T{// lone comments
|
|||
// in composite lit
|
||||
}
|
||||
|
||||
func _() {}
|
||||
|
||||
//
|
||||
func _() {}
|
||||
|
||||
/* This comment is the last entry in this file. It must be printed and should be followed by a newline */
|
||||
|
|
|
|||
Loading…
Reference in New Issue