From: Alan Donovan Date: Wed, 16 Apr 2014 20:17:50 +0000 (-0400) Subject: go/scanner: interpret //line directives sans filename sensibly, second try. X-Git-Tag: go1.3beta1~46 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0de521d111b88b2bc6466a4e1f29a8a284c0b3ee;p=gostls13.git 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 --- 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