mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.typeparams] cmd/compile/internal/types2: don't crash if import path is missing
In package syntax: - fix parser appendGroup to not add nil entries - non-string paths are syntax errors per the spec; report in parser - document ImportDecl.Path invariants In package types2: - guard against absent paths In package gc: - guard against absent paths Fixes #43190. Change-Id: Ic6a06f6a96b7f519feaa1ceaf4376fc5ab0f0129 Reviewed-on: https://go-review.googlesource.com/c/go/+/278114 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
14e4267c34
commit
6b18081d01
5 changed files with 34 additions and 15 deletions
|
|
@ -499,21 +499,16 @@ func (p *parser) appendGroup(list []Decl, f func(*Group) Decl) []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
|
||||
}
|
||||
|
||||
|
|
@ -540,8 +535,13 @@ func (p *parser) importDecl(group *Group) Decl {
|
|||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue