From: Robert Griesemer Date: Fri, 21 Jun 2013 22:09:04 +0000 (-0700) Subject: go/parser: always provide a non-nil path for imports X-Git-Tag: go1.2rc2~1203 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fc1e298ba1dfa404e2036d7461110511fdc28422;p=gostls13.git 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 --- diff --git a/src/pkg/go/parser/parser.go b/src/pkg/go/parser/parser.go index 809687fef9..721ab58570 100644 --- a/src/pkg/go/parser/parser.go +++ b/src/pkg/go/parser/parser.go @@ -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)