mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: fix contrived line number errors
If a general comment contains multiple newline characters, we can't simply unread one and then re-lex it via the general whitespace lexing phase, because then we'll reset lineno to the line before the "*/" marker, rather than keeping it where we found the "/*" marker. Also, for processing imports, call importfile before advancing the lexer with p.next(), so that lineno reflects the line where we found the import path, and not the token afterwards. Fixes #14520. Change-Id: I785a2d83d632280113d4b757de0d57c88ba2caf4 Reviewed-on: https://go-review.googlesource.com/19934 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
a131a66e63
commit
af558acc47
3 changed files with 38 additions and 22 deletions
|
|
@ -333,20 +333,22 @@ func (p *parser) importdcl() {
|
|||
}
|
||||
|
||||
line := int32(parserline())
|
||||
path := p.val
|
||||
p.next()
|
||||
|
||||
importfile(&path, p.indent)
|
||||
if importpkg == nil {
|
||||
// We need to clear importpkg before calling p.next(),
|
||||
// otherwise it will affect lexlineno.
|
||||
// TODO(mdempsky): Fix this clumsy API.
|
||||
importfile(&p.val, p.indent)
|
||||
ipkg := importpkg
|
||||
importpkg = nil
|
||||
|
||||
p.next()
|
||||
if ipkg == nil {
|
||||
if nerrors == 0 {
|
||||
Fatalf("phase error in import")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
ipkg := importpkg
|
||||
importpkg = nil
|
||||
|
||||
ipkg.Direct = true
|
||||
|
||||
if my == nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue