mirror of
https://github.com/golang/go.git
synced 2025-10-27 06:44:13 +00:00
[dev.typeparams] cmd/compile: point StructKeyExpr at the types.Field
When constructing struct literals, importers need a way to specify precisely which field to initialize without worrying about visibility or those fields being blank. (A blank field doesn't actually need to be initialized, but the expression needs to be evaluated still, and with the right order-of-operations.) This CL changes StructKeyExpr's Field field to point directly to the corresponding types.Field, rather than merely holding a copy of its Sym and Offset. This is akin to past changes to add SelectorExpr.Selection. Change-Id: I95b72b1788f73206fcebc22b456cf6b1186db6a7 Reviewed-on: https://go-review.googlesource.com/c/go/+/325031 Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
parent
bad388744b
commit
a94e4f5a85
9 changed files with 107 additions and 112 deletions
|
|
@ -324,20 +324,18 @@ func NewKeyExpr(pos src.XPos, key, value Node) *KeyExpr {
|
|||
// A StructKeyExpr is an Field: Value composite literal key.
|
||||
type StructKeyExpr struct {
|
||||
miniExpr
|
||||
Field *types.Sym
|
||||
Value Node
|
||||
Offset int64
|
||||
Field *types.Field
|
||||
Value Node
|
||||
}
|
||||
|
||||
func NewStructKeyExpr(pos src.XPos, field *types.Sym, value Node) *StructKeyExpr {
|
||||
func NewStructKeyExpr(pos src.XPos, field *types.Field, value Node) *StructKeyExpr {
|
||||
n := &StructKeyExpr{Field: field, Value: value}
|
||||
n.pos = pos
|
||||
n.op = OSTRUCTKEY
|
||||
n.Offset = types.BADWIDTH
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *StructKeyExpr) Sym() *types.Sym { return n.Field }
|
||||
func (n *StructKeyExpr) Sym() *types.Sym { return n.Field.Sym }
|
||||
|
||||
// An InlinedCallExpr is an inlined function call.
|
||||
type InlinedCallExpr struct {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue