Skip to content

Commit 1e4e096

Browse files
committed
cmd/compile: remove parser lineno hack for issue #13267
After golang.org/cl/19652 removed the bizarre lexlineno{++,--} statements for parsing canned imports, this hack for #13267 is no longer necessary: $ echo -n 0 > /tmp/0.go $ go tool compile /tmp/0.go /tmp/0.go:1: syntax error: package statement must be first Apparently setting lexlineno to 2 while parsing the canned imports caused prevlineno and lineno to also be set to 2. After we finished parsing imports and restored lexlineno to 1, since "package" is the first token in a source file, we'll have fixed lineno = 1, but prevlineno was still set to 2. Change-Id: Ibcc49fe3402264819b9abb53505631f7a0ad4a36 Reviewed-on: https://go-review.googlesource.com/19859 Reviewed-by: Robert Griesemer <gri@golang.org>
1 parent e360f7c commit 1e4e096

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/cmd/compile/internal/gc/parser.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,11 @@ func (p *parser) package_() {
280280
defer p.trace("package_")()
281281
}
282282

283-
if p.got(LPACKAGE) {
284-
mkpackage(p.sym().Name)
285-
} else {
286-
prevlineno = lineno // see issue #13267
283+
if !p.got(LPACKAGE) {
287284
p.syntax_error("package statement must be first")
288285
errorexit()
289286
}
287+
mkpackage(p.sym().Name)
290288
}
291289

292290
// ImportDecl = "import" ( ImportSpec | "(" { ImportSpec ";" } ")" ) .

0 commit comments

Comments
 (0)