diff --git a/src/cmd/compile/internal/walk/assign.go b/src/cmd/compile/internal/walk/assign.go index c8342b4fa432d8..3abf2a060c8a03 100644 --- a/src/cmd/compile/internal/walk/assign.go +++ b/src/cmd/compile/internal/walk/assign.go @@ -341,6 +341,9 @@ func ascompatee(op ir.Op, nl, nr []ir.Node) []ir.Node { break } + walkStmtList(l.Init()) + early.Append(ir.TakeInit(l)...) + var name *ir.Name switch l.Op() { default: diff --git a/test/fixedbugs/issue45706.go b/test/fixedbugs/issue45706.go new file mode 100644 index 00000000000000..facf488b3de989 --- /dev/null +++ b/test/fixedbugs/issue45706.go @@ -0,0 +1,16 @@ +// 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 + +var i int +var arr []*int +var f func() int + +func g() { + for i, *(arr[f()]) = range []int{} { + } +}