aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2021-04-22 17:14:10 +0700
committerCuong Manh Le <cuong.manhle.vn@gmail.com>2021-04-23 05:10:41 +0000
commitd310b2a6b8a66eeb5953b1e682cf27669c8a08c2 (patch)
tree6556c0a96372c32b7a6d25fab3b1705412fe74f2 /test
parent1b0a0316802b8048d69da49dc23c5a5ab08e8ae8 (diff)
downloadgo-d310b2a6b8a66eeb5953b1e682cf27669c8a08c2.tar.gz
go-d310b2a6b8a66eeb5953b1e682cf27669c8a08c2.zip
cmd/compile: set correct Defn for inlined vars
Currently, when copying definition node of an inlined var, we do not update var Defn field to point to new copied node. That causes all inlined vars point to the same Defn, and ir.StaticValue can not find inlined var in the lhs of its definition. clovar creates new ONAME node for local variables or params of closure inside inlined function, by copying most of the old node fields. So the new Node.Defn is not modified, its lhs still refer to old node instead of new one. To fix this, we need to do two things: - In subst.clovar, set a dummy Defn node for inlvar - During subst.node, when seeing OAS/OAS2 nodes, after substituting, we check if any node in lhs has the dummy Defn, then set it to the current OAS/OAS2 node. Fixes #45606 Change-Id: Ib517b753a7643756dcd61d36deae60f1a0fc53c5 Reviewed-on: https://go-review.googlesource.com/c/go/+/312630 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: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue45606.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/fixedbugs/issue45606.go b/test/fixedbugs/issue45606.go
new file mode 100644
index 0000000000..1b52b4e7d5
--- /dev/null
+++ b/test/fixedbugs/issue45606.go
@@ -0,0 +1,17 @@
+// 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 x() {
+ func() func() {
+ return func() {
+ f := func() {}
+ g, _ := f, 0
+ g()
+ }
+ }()()
+}