]> Cypherpunks repositories - gostls13.git/commitdiff
fix for long label names impacting column width of previous lines
authorRobert Griesemer <gri@golang.org>
Wed, 28 Oct 2009 17:14:59 +0000 (10:14 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 28 Oct 2009 17:14:59 +0000 (10:14 -0700)
R=rsc
http://go/go-review/1013017

src/pkg/go/printer/printer.go
src/pkg/go/printer/testdata/statements.go
src/pkg/go/printer/testdata/statements.golden

index 01f45356f61e371d765ae38757c3a5891abceb77..50dcffd866455fe21c18da1a6069e68b12a18920 100644 (file)
@@ -418,7 +418,12 @@ func (p *printer) writeWhitespace(n int) {
                        // part of the comment whitespace prefix and the comment
                        // will be positioned correctly indented.
                        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
                                continue;
                        }
index 85cb5989ce97f06900381c3a1a75e97c2b22f2da..c58131f0b687c9c8888d9ca33114245b3f641498 100644 (file)
@@ -156,3 +156,20 @@ func _() {
                _ = 0;
        }
 }
+
+
+func _() {
+       if {
+               _ = 0;
+       }
+       _ = 0;  // the indentation here should not be affected by the long label name
+AnOverlongLabel:
+       _ = 0;
+       
+       if {
+               _ = 0;
+       }
+       _ = 0;
+
+L:     _ = 0;
+}
index 3d8d424c10846ff578ffaa30414edbba9df4c637..16392806ae03d1a039ff27f91f5aba7011d558d4 100644 (file)
@@ -174,3 +174,20 @@ func _() {
                _ = 0;
        }
 }
+
+
+func _() {
+       if {
+               _ = 0;
+       }
+       _ = 0;  // the indentation here should not be affected by the long label name
+AnOverlongLabel:
+       _ = 0;
+
+       if {
+               _ = 0;
+       }
+       _ = 0;
+
+L:     _ = 0;
+}