}
func (p *noder) importDecl(imp *syntax.ImportDecl) {
- if imp.Path.Bad {
+ if imp.Path == nil || imp.Path.Bad {
return // avoid follow-on errors if there was a syntax error
}
ImportDecl struct {
Group *Group // nil means not part of a group
Pragma Pragma
- LocalPkgName *Name // including "."; nil means no rename present
- Path *BasicLit
+ LocalPkgName *Name // including "."; nil means no rename present
+ Path *BasicLit // Path.Bad || Path.Kind == StringLit; nil means no path
decl
}
p.clearPragma()
p.next() // must consume "(" after calling clearPragma!
p.list(_Semi, _Rparen, func() bool {
- list = append(list, f(g))
+ if x := f(g); x != nil {
+ list = append(list, x)
+ }
return false
})
} else {
- list = append(list, f(nil))
- }
-
- if debug {
- for _, d := range list {
- if d == nil {
- panic("nil list entry")
- }
+ if x := f(nil); x != nil {
+ list = append(list, x)
}
}
-
return list
}
if d.Path == nil {
p.syntaxError("missing import path")
p.advance(_Semi, _Rparen)
- return nil
+ return d
+ }
+ if !d.Path.Bad && d.Path.Kind != StringLit {
+ p.syntaxError("import path must be a string")
+ d.Path.Bad = true
}
+ // d.Path.Bad || d.Path.Kind == StringLit
return d
}
--- /dev/null
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+import ; // ERROR missing import path
+import
+var /* ERROR missing import path */ _ int
+import .; // ERROR missing import path
+
+import ()
+import (.) // ERROR missing import path
+import (
+ "fmt"
+ .
+) // ERROR missing import path
+
+var _ = fmt.Println // avoid imported but not used error
switch s := decl.(type) {
case *syntax.ImportDecl:
// import package
- if s.Path.Bad {
+ if s.Path == nil || s.Path.Bad {
continue // error reported during parsing
}
path, err := validatedImportPath(s.Path.Value)