var ident *ast.Ident
switch p.tok {
+ case token.IDENT:
+ ident = p.parseIdent()
case token.PERIOD:
ident = &ast.Ident{NamePos: p.pos, Name: "."}
p.next()
- case token.IDENT:
- ident = p.parseIdent()
}
pos := p.pos
if p.tok == token.STRING {
path = p.lit
p.next()
+ } else if p.tok.IsLiteral() {
+ p.error(pos, "import path must be a string")
+ p.next()
} else {
- p.expect(token.STRING) // use expect() error handling
+ p.error(pos, "missing import path")
+ // don't advance if we're at a semicolon or closing parenthesis
+ if p.tok != token.SEMICOLON && p.tok != token.RPAREN {
+ p.next()
+ }
}
p.expectSemi() // call before accessing p.linecomment
switch d := d.(type) {
case importDecl:
// import package
+ if d.spec.Path.Value == "" {
+ return // error reported by parser
+ }
path, err := validatedImportPath(d.spec.Path.Value)
if err != nil {
check.errorf(d.spec.Path, _BadImportPath, "invalid import path (%s)", err)
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// Most of the errors below are actually produced by the parser, but we check
+// The errors below are produced by the parser, but we check
// them here for consistency with the types2 tests.
package p
-import ; /* ERROR invalid import path */ /* ERROR expected 'STRING' */
-import // ERROR expected ';'
-var _ int
-import /* ERROR expected declaration */ .;
+import ; // ERROR missing import path
+import ';' // ERROR import path must be a string
+// TODO(gri) The parser should accept mixing imports with other
+// top-level declarations for better error recovery.
+// var _ int
+import . ; // ERROR missing import path
import ()
-import (.)
+import (.) // ERROR missing import path
import (
"fmt"
.
-)
+) // ERROR missing import path
-var _ = fmt /* ERROR "undeclared name" */ .Println
+var _ = fmt.Println