mirror of
https://github.com/golang/go
synced 2024-11-25 06:07:58 -07:00
fix for long label names impacting column width of previous lines
R=rsc http://go/go-review/1013017
This commit is contained in:
parent
d2829faa7c
commit
5a02eb65ef
@ -418,7 +418,12 @@ func (p *printer) writeWhitespace(n int) {
|
|||||||
// part of the comment whitespace prefix and the comment
|
// part of the comment whitespace prefix and the comment
|
||||||
// will be positioned correctly indented.
|
// will be positioned correctly indented.
|
||||||
if i+1 < n && p.buffer[i+1] == unindent {
|
if i+1 < n && p.buffer[i+1] == unindent {
|
||||||
p.buffer[i], p.buffer[i+1] = unindent, ch;
|
// Use a formfeed to terminate the current section.
|
||||||
|
// Otherwise, a long label name on the next line leading
|
||||||
|
// to a wide column may increase the indentation column
|
||||||
|
// of lines before the label; effectively leading to wrong
|
||||||
|
// indentation.
|
||||||
|
p.buffer[i], p.buffer[i+1] = unindent, formfeed;
|
||||||
i--; // do it again
|
i--; // do it again
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
17
src/pkg/go/printer/testdata/statements.go
vendored
17
src/pkg/go/printer/testdata/statements.go
vendored
@ -156,3 +156,20 @@ func _() {
|
|||||||
_ = 0;
|
_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
if {
|
||||||
|
_ = 0;
|
||||||
|
}
|
||||||
|
_ = 0; // the indentation here should not be affected by the long label name
|
||||||
|
AnOverlongLabel:
|
||||||
|
_ = 0;
|
||||||
|
|
||||||
|
if {
|
||||||
|
_ = 0;
|
||||||
|
}
|
||||||
|
_ = 0;
|
||||||
|
|
||||||
|
L: _ = 0;
|
||||||
|
}
|
||||||
|
17
src/pkg/go/printer/testdata/statements.golden
vendored
17
src/pkg/go/printer/testdata/statements.golden
vendored
@ -174,3 +174,20 @@ func _() {
|
|||||||
_ = 0;
|
_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
if {
|
||||||
|
_ = 0;
|
||||||
|
}
|
||||||
|
_ = 0; // the indentation here should not be affected by the long label name
|
||||||
|
AnOverlongLabel:
|
||||||
|
_ = 0;
|
||||||
|
|
||||||
|
if {
|
||||||
|
_ = 0;
|
||||||
|
}
|
||||||
|
_ = 0;
|
||||||
|
|
||||||
|
L: _ = 0;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user