1
0
mirror of https://github.com/golang/go synced 2024-11-14 07:20:22 -07:00

go/parser: always provide a non-nil path for imports

The go/ast ImportSpec always requires a non-nil path.

R=adonovan
CC=golang-dev
https://golang.org/cl/10402047
This commit is contained in:
Robert Griesemer 2013-06-21 15:09:04 -07:00
parent 279c48444a
commit fc1e298ba1

View File

@ -2151,12 +2151,13 @@ func (p *parser) parseImportSpec(doc *ast.CommentGroup, _ token.Token, _ int) as
ident = p.parseIdent() ident = p.parseIdent()
} }
var path *ast.BasicLit pos := p.pos
var path string
if p.tok == token.STRING { if p.tok == token.STRING {
if !isValidImport(p.lit) { path = p.lit
p.error(p.pos, "invalid import path: "+p.lit) if !isValidImport(path) {
p.error(pos, "invalid import path: "+path)
} }
path = &ast.BasicLit{ValuePos: p.pos, Kind: p.tok, Value: p.lit}
p.next() p.next()
} else { } else {
p.expect(token.STRING) // use expect() error handling p.expect(token.STRING) // use expect() error handling
@ -2167,7 +2168,7 @@ func (p *parser) parseImportSpec(doc *ast.CommentGroup, _ token.Token, _ int) as
spec := &ast.ImportSpec{ spec := &ast.ImportSpec{
Doc: doc, Doc: doc,
Name: ident, Name: ident,
Path: path, Path: &ast.BasicLit{ValuePos: pos, Kind: token.STRING, Value: path},
Comment: p.lineComment, Comment: p.lineComment,
} }
p.imports = append(p.imports, spec) p.imports = append(p.imports, spec)