]> Cypherpunks repositories - gostls13.git/commitdiff
gofmt: fix //line handling
authorRuss Cox <rsc@golang.org>
Fri, 14 Oct 2011 19:54:45 +0000 (15:54 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 14 Oct 2011 19:54:45 +0000 (15:54 -0400)
Fixes #2369.

R=gri
CC=golang-dev
https://golang.org/cl/5275048

src/cmd/gofmt/gofmt_test.go
src/cmd/gofmt/testdata/comments.golden [new file with mode: 0644]
src/cmd/gofmt/testdata/comments.input [new file with mode: 0644]
src/pkg/go/scanner/scanner.go

index 87b02dad7dfec23dc0d251812e4c1c0b2d0d10ce..6587f06a02dad8ac6b09c81c888f86f8e537713b 100644 (file)
@@ -77,6 +77,7 @@ var tests = []struct {
        {"testdata/rewrite1.input", "-r=Foo->Bar"},
        {"testdata/rewrite2.input", "-r=int->bool"},
        {"testdata/stdin*.input", "-stdin"},
+       {"testdata/comments.input", ""},
 }
 
 func TestRewrite(t *testing.T) {
diff --git a/src/cmd/gofmt/testdata/comments.golden b/src/cmd/gofmt/testdata/comments.golden
new file mode 100644 (file)
index 0000000..ad6bcaf
--- /dev/null
@@ -0,0 +1,9 @@
+package main
+
+func main() {}
+
+// comment here
+
+func f() {}
+
+//line foo.go:1
diff --git a/src/cmd/gofmt/testdata/comments.input b/src/cmd/gofmt/testdata/comments.input
new file mode 100644 (file)
index 0000000..ad6bcaf
--- /dev/null
@@ -0,0 +1,9 @@
+package main
+
+func main() {}
+
+// comment here
+
+func f() {}
+
+//line foo.go:1
index 9f855fc197ff6b3482fc9040410fd3a8ad358574..589ec68a67843f9f61b759de521aa65fb2bec520 100644 (file)
@@ -151,7 +151,7 @@ func (S *Scanner) interpretLineComment(text []byte) {
                                        filename = filepath.Join(S.dir, filename)
                                }
                                // update scanner position
-                               S.file.AddLineInfo(S.lineOffset, filename, line-1) // -1 since comment applies to next line
+                               S.file.AddLineInfo(S.lineOffset+len(text)+1, filename, line) // +len(text)+1 since comment applies to next line
                        }
                }
        }