mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: only allow integer expressions as keys in array literals
Fixes #16439 Updates #16679 Change-Id: Idff4b313f29351866b1a649786501adee85fd580 Reviewed-on: https://go-review.googlesource.com/29011 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
c2735039f3
commit
7f1bc53379
4 changed files with 56 additions and 47 deletions
|
|
@ -1226,10 +1226,11 @@ func initplan(n *Node) {
|
|||
|
||||
case OARRAYLIT, OSLICELIT:
|
||||
for _, a := range n.List.Slice() {
|
||||
if a.Op != OKEY || !smallintconst(a.Left) {
|
||||
index := nonnegintconst(a.Left)
|
||||
if a.Op != OKEY || index < 0 {
|
||||
Fatalf("initplan fixedlit")
|
||||
}
|
||||
addvalue(p, n.Type.Elem().Width*a.Left.Int64(), a.Right)
|
||||
addvalue(p, index*n.Type.Elem().Width, a.Right)
|
||||
}
|
||||
|
||||
case OSTRUCTLIT:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue