]> Cypherpunks repositories - gostls13.git/commitdiff
go/parser: always provide a non-nil path for imports
authorRobert Griesemer <gri@golang.org>
Fri, 21 Jun 2013 22:09:04 +0000 (15:09 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 21 Jun 2013 22:09:04 +0000 (15:09 -0700)
The go/ast ImportSpec always requires a non-nil path.

R=adonovan
CC=golang-dev
https://golang.org/cl/10402047

src/pkg/go/parser/parser.go

index 809687fef9e67d5acc3c3b49209124a46dfdd215..721ab58570886cff64df443b2ea647236dfd32de 100644 (file)
@@ -2151,12 +2151,13 @@ func (p *parser) parseImportSpec(doc *ast.CommentGroup, _ token.Token, _ int) as
                ident = p.parseIdent()
        }
 
-       var path *ast.BasicLit
+       pos := p.pos
+       var path string
        if p.tok == token.STRING {
-               if !isValidImport(p.lit) {
-                       p.error(p.pos, "invalid import path: "+p.lit)
+               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()
        } else {
                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{
                Doc:     doc,
                Name:    ident,
-               Path:    path,
+               Path:    &ast.BasicLit{ValuePos: pos, Kind: token.STRING, Value: path},
                Comment: p.lineComment,
        }
        p.imports = append(p.imports, spec)