When seeing Key:Value expression in slice literal, the compiler only
needs to emit tmp var for the Value, not the whole expression.
Fixes #49240
Change-Id: I7bda3c796a93c0fa1974f7c5930f38025dfa665c
Reviewed-on: https://go-review.googlesource.com/c/go/+/360055
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
if arg := *argp; arg.Op() == ir.OSLICELIT {
list := arg.(*ir.CompLitExpr).List
for i := range list {
- visit(arg.Pos(), &list[i])
+ el := &list[i]
+ if list[i].Op() == ir.OKEY {
+ el = &list[i].(*ir.KeyExpr).Value
+ }
+ visit(arg.Pos(), el)
}
} else {
visit(call.Pos(), argp)
--- /dev/null
+// compile
+
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+func f() {
+ go copy([]int{1: 0}, []int{})
+}