]> Cypherpunks repositories - gostls13.git/commitdiff
go/scanner: interpret //line directives sans filename sensibly, second try.
authorAlan Donovan <adonovan@google.com>
Wed, 16 Apr 2014 20:17:50 +0000 (16:17 -0400)
committerAlan Donovan <adonovan@google.com>
Wed, 16 Apr 2014 20:17:50 +0000 (16:17 -0400)
A //line directive without a filename now denotes the empty
filename, not the current directory (the Go 1.2 behaviour) nor
the previous //line's filename (the behaviour since CL
86990044).

They should never appear (but they do, e.g. due to a bug in godoc).

Fixes #7765

LGTM=gri, rsc
R=rsc, gri
CC=golang-codereviews
https://golang.org/cl/88160050

src/pkg/go/scanner/scanner.go
src/pkg/go/scanner/scanner_test.go

index c83e4fa8160ac8c5f43aaf5968f296ff4e225566..cec82ea10efa52bde92a290062f57cfeb0418974 100644 (file)
@@ -150,10 +150,7 @@ func (s *Scanner) interpretLineComment(text []byte) {
                        if line, err := strconv.Atoi(string(text[i+1:])); err == nil && line > 0 {
                                // valid //line filename:line comment
                                filename := string(bytes.TrimSpace(text[len(prefix):i]))
-                               if filename == "" {
-                                       // assume same file as for previous line
-                                       filename = s.file.Position(s.file.Pos(s.lineOffset)).Filename
-                               } else {
+                               if filename != "" {
                                        filename = filepath.Clean(filename)
                                        if !filepath.IsAbs(filename) {
                                                // make filename relative to current directory
index 55e55abaecf90f5ec9912ffc5b66c8bb2593090f..fc450d8a6eb0db6dd854f116c3800d5ccfcc7ffa 100644 (file)
@@ -493,9 +493,8 @@ var segments = []segment{
        {"\nline3  //line File1.go:100", filepath.Join("dir", "TestLineComments"), 3}, // bad line comment, ignored
        {"\nline4", filepath.Join("dir", "TestLineComments"), 4},
        {"\n//line File1.go:100\n  line100", filepath.Join("dir", "File1.go"), 100},
-       {"\n//line :42\n  line1", "dir/File1.go", 42},
+       {"\n//line  \t :42\n  line1", "", 42},
        {"\n//line File2.go:200\n  line200", filepath.Join("dir", "File2.go"), 200},
-       {"\n//line  \t :123\n  line1", "dir/File2.go", 123},
        {"\n//line foo\t:42\n  line42", filepath.Join("dir", "foo"), 42},
        {"\n //line foo:42\n  line44", filepath.Join("dir", "foo"), 44},           // bad line comment, ignored
        {"\n//line foo 42\n  line46", filepath.Join("dir", "foo"), 46},            // bad line comment, ignored