Commit c4e27b7c authored by Robert Griesemer's avatar Robert Griesemer

gofmt, go/printer: update internal estimated position correctly

Fixes #1089.

R=rsc
CC=golang-dev
https://golang.org/cl/2172043
parent ba517540
......@@ -209,6 +209,11 @@ func (p *printer) write(data []byte) {
case tabwriter.Escape:
p.escape = !p.escape
// ignore escape chars introduced by printer - they are
// invisible and must not affect p.pos (was issue #1089)
p.pos.Offset--
p.pos.Column--
}
}
......
......@@ -431,6 +431,38 @@ func _() {
}
// Comments immediately adjacent to punctuation (for which the go/printer
// may obly have estimated position information) must remain after the punctuation.
func _() {
_ = T{
1, // comment after comma
2, /* comment after comma */
3, // comment after comma
}
_ = T{
1, // comment after comma
2, /* comment after comma */
3, // comment after comma
}
_ = T{
/* comment before literal */ 1,
2, /* comment before comma - ok to move after comma */
3, /* comment before comma - ok to move after comma */
}
for i = 0; // comment after semicolon
i < 9; /* comment after semicolon */
i++ { // comment after opening curly brace
}
// TODO(gri) the last comment in this example should be aligned */
for i = 0; // comment after semicolon
i < 9; /* comment before semicolon - ok to move after semicolon */
i++ /* comment before opening curly brace */ {
}
}
// Line comments with tabs
func _() {
var finput *bufio.Reader // input file
......
......@@ -429,6 +429,40 @@ func _() {
/* closing curly brace should be on new line */ }
// Comments immediately adjacent to punctuation (for which the go/printer
// may obly have estimated position information) must remain after the punctuation.
func _() {
_ = T{
1, // comment after comma
2, /* comment after comma */
3 , // comment after comma
}
_ = T{
1 ,// comment after comma
2 ,/* comment after comma */
3,// comment after comma
}
_ = T{
/* comment before literal */1,
2/* comment before comma - ok to move after comma */,
3 /* comment before comma - ok to move after comma */ ,
}
for
i=0;// comment after semicolon
i<9;/* comment after semicolon */
i++{// comment after opening curly brace
}
// TODO(gri) the last comment in this example should be aligned */
for
i=0;// comment after semicolon
i<9/* comment before semicolon - ok to move after semicolon */;
i++ /* comment before opening curly brace */ {
}
}
// Line comments with tabs
func _() {
var finput *bufio.Reader // input file
......
......@@ -335,7 +335,6 @@ func _() {
2,
3,
)
// TODO(gri) the cases below are not correct yet
f(1,
2,
3) // comment
......@@ -348,8 +347,7 @@ func _() {
3) // comment
f(1,
2,
3 // comment
,
3, // comment
)
}
......
......@@ -328,7 +328,6 @@ func _() {
2,
3,
)
// TODO(gri) the cases below are not correct yet
f(1,
2,
3) // comment
......
......@@ -335,7 +335,6 @@ func _() {
2,
3,
)
// TODO(gri) the cases below are not correct yet
f(1,
2,
3) // comment
......@@ -348,8 +347,7 @@ func _() {
3) // comment
f(1,
2,
3 // comment
,
3, // comment
)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment