mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: fix isStaticCompositeLiteral reports wrong for struct field
golang.org/cl/174498 add ONAME case to isStaticCompositeLiteral, to
detect global variable as compile-time constant.
It does report wrong for struct field, e.g:
o := one{i: two{i: 42}.i}
field i in two{i: 42} was reported as static composite literal, while it
should not.
In general, adding ONAME case for isStaticCompositeLiteral is probably
wrong.
Fixes #31782
Change-Id: Icde7d43bbb002b75df5c52b948b7126a4265e07b
Reviewed-on: https://go-review.googlesource.com/c/go/+/174837
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
689ee112df
commit
004fb5cb8d
3 changed files with 25 additions and 2 deletions
|
|
@ -650,8 +650,6 @@ func getdyn(n *Node, top bool) initGenType {
|
|||
// isStaticCompositeLiteral reports whether n is a compile-time constant.
|
||||
func isStaticCompositeLiteral(n *Node) bool {
|
||||
switch n.Op {
|
||||
case ONAME:
|
||||
return n.Class() == PEXTERN && n.Name != nil && n.Name.Readonly()
|
||||
case OSLICELIT:
|
||||
return false
|
||||
case OARRAYLIT:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue