From 8486ced8b09f4425bfd85e09b021dc78f93aea08 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Fri, 20 Aug 2021 10:19:28 -0700 Subject: cmd/compile: copy captured dictionary var to local var When starting a closure that needs a dictionary, copy the closure variable to a local variable. This lets child closures capture that dictionary variable correctly. This is a better fix for #47684, which does not cause problems like #47723. Fixes #47723 Update #47684 Change-Id: Ib5d9ffc68a5142e28daa7d0d75683e7a35508540 Reviewed-on: https://go-review.googlesource.com/c/go/+/343871 Trust: Keith Randall Trust: Dan Scales Run-TryBot: Keith Randall TryBot-Result: Go Bot Reviewed-by: Dan Scales --- test/typeparam/issue47723.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/typeparam/issue47723.go (limited to 'test') diff --git a/test/typeparam/issue47723.go b/test/typeparam/issue47723.go new file mode 100644 index 0000000000..9ef60402b2 --- /dev/null +++ b/test/typeparam/issue47723.go @@ -0,0 +1,23 @@ +// run -gcflags=-G=3 + +// 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 main + +func f[_ any]() int { + var a [1]int + _ = func() int { + return func() int { + return 0 + }() + }() + return a[func() int { + return 0 + }()] +} + +func main() { + f[int]() +} -- cgit v1.2.3-54-g00ecf