mirror of
https://github.com/golang/go
synced 2024-11-23 09:40:04 -07:00
go/parser: resolve the type name when parsing a composite lit value
parsePrimaryExpr has to be careful to resolve identifiers used in composite expressions when parsing in LHS mode. It missed the literal type name. Fixes #45136 Change-Id: I3e12f91e3ef5fdb43faa436cdf1240eb3293fe1a Reviewed-on: https://go-review.googlesource.com/c/go/+/304451 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
0fdd371e6b
commit
c3ec79bca9
@ -1804,6 +1804,11 @@ func (p *parser) parsePrimaryExpr(lhs bool) (x ast.Expr) {
|
||||
p.error(t.Pos(), "cannot parenthesize type in composite literal")
|
||||
// already progressed, no need to advance
|
||||
}
|
||||
if lhs {
|
||||
// An error has already been reported above, but try to resolve the 'T'
|
||||
// in (T){...} anyway.
|
||||
p.resolve(t)
|
||||
}
|
||||
x = p.parseLiteralValue(x)
|
||||
default:
|
||||
return
|
||||
|
10
src/go/parser/testdata/resolution/issue45136.src
vendored
10
src/go/parser/testdata/resolution/issue45136.src
vendored
@ -12,17 +12,15 @@ func _ /* =@blank */ () {
|
||||
var foo /* =@foo */ = "foo"
|
||||
obj /* @obj */ ["foo"]
|
||||
obj /* @obj */ .run()
|
||||
|
||||
// TODO(#45136): the next two statements are missing objects.
|
||||
obj{
|
||||
obj /* @obj */ {
|
||||
name: foo /* @foo */,
|
||||
}
|
||||
obj{
|
||||
obj /* @obj */ {
|
||||
name: "bar",
|
||||
}.run()
|
||||
|
||||
var _ /* @=blank4 */ = File{key: obj /* @obj */{}}
|
||||
var _ /* @=blank3 */ = File{obj{}}
|
||||
var _ /* @=blank4 */ = File{key: obj /* @obj */ {}}
|
||||
var _ /* @=blank3 */ = File{obj /* @obj */ {}}
|
||||
|
||||
[]obj /* @obj */ {foo /* @foo */}
|
||||
x /* =@x1 */ := obj /* @obj */{}
|
||||
|
Loading…
Reference in New Issue
Block a user