for _, x := range as2init.Lhs {
count[x.(*ir.Name)] = 0
}
+
+ hasNonTrivialClosure := false
ir.Visit(as2body.Rhs[0], func(n ir.Node) {
if name, ok := n.(*ir.Name); ok {
if c, ok := count[name]; ok {
count[name] = c + 1
}
}
+ if clo, ok := n.(*ir.ClosureExpr); ok {
+ hasNonTrivialClosure = hasNonTrivialClosure || !ir.IsTrivialClosure(clo)
+ }
})
+
+ // If there's a non-trivial closure, it has captured the param,
+ // so we can't substitute arg for param.
+ if hasNonTrivialClosure {
+ return false
+ }
+
for name, c := range count {
if c > 1 {
// Check whether corresponding initializer can be repeated.
--- /dev/null
+// Copyright 2022 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 a
+
+type A struct {
+ New func() any
+}
+
+func NewA(i int) *A {
+ return &A{
+ New: func() any {
+ _ = i
+ return nil
+ },
+ }
+}
--- /dev/null
+// Copyright 2022 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 b
+
+import "./a"
+
+var _ = a.NewA(0)
--- /dev/null
+// compiledir
+
+// Copyright 2022 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 ignored