diff options
author | Alan Donovan <adonovan@google.com> | 2014-04-16 16:17:50 -0400 |
---|---|---|
committer | Alan Donovan <adonovan@google.com> | 2014-04-16 16:17:50 -0400 |
commit | 0de521d111b88b2bc6466a4e1f29a8a284c0b3ee (patch) | |
tree | dc3ae80a1c9e11eb36887d047f10c8807597f61d | |
parent | 3af8d6fa4ae61a56350d09b886a9f18937fa5fb9 (diff) | |
download | go-0de521d111b88b2bc6466a4e1f29a8a284c0b3ee.tar.gz go-0de521d111b88b2bc6466a4e1f29a8a284c0b3ee.zip |
go/scanner: interpret //line directives sans filename sensibly, second try.
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
-rw-r--r-- | src/pkg/go/scanner/scanner.go | 5 | ||||
-rw-r--r-- | src/pkg/go/scanner/scanner_test.go | 3 |
2 files changed, 2 insertions, 6 deletions
diff --git a/src/pkg/go/scanner/scanner.go b/src/pkg/go/scanner/scanner.go index c83e4fa816..cec82ea10e 100644 --- a/src/pkg/go/scanner/scanner.go +++ b/src/pkg/go/scanner/scanner.go @@ -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 diff --git a/src/pkg/go/scanner/scanner_test.go b/src/pkg/go/scanner/scanner_test.go index 55e55abaec..fc450d8a6e 100644 --- a/src/pkg/go/scanner/scanner_test.go +++ b/src/pkg/go/scanner/scanner_test.go @@ -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 |