]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.19] cmd/compile: fix missing typecheck for static initialization...
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 14 Nov 2022 16:11:30 +0000 (23:11 +0700)
committerMichael Pratt <mpratt@google.com>
Fri, 9 Dec 2022 21:06:32 +0000 (21:06 +0000)
CL 440455 fixed missing walk pass for static initialization slice.
However, slicelit may produce un-typechecked node, thus we need to do
typecheck for sinit before calling walkStmtList.

Fixes #56744

Change-Id: I40730cebcd09f2be4389d71c5a90eb9a060e4ab7
Reviewed-on: https://go-review.googlesource.com/c/go/+/450215
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/451155
Reviewed-by: Joedian Reid <joedian@golang.org>
src/cmd/compile/internal/walk/complit.go
test/fixedbugs/issue56727.go [new file with mode: 0644]

index 603c479a089913c60bf960cd57594f246a592e58..71ab4700e03ccec40c75194de3b4ab8c34d9198a 100644 (file)
@@ -243,6 +243,7 @@ func fixedlit(ctxt initContext, kind initKind, n *ir.CompLitExpr, var_ ir.Node,
                                        // confuses about variables lifetime. So making sure those expressions
                                        // are ordered correctly here. See issue #52673.
                                        orderBlock(&sinit, map[string][]*ir.Name{})
+                                       typecheck.Stmts(sinit)
                                        walkStmtList(sinit)
                                }
                                init.Append(sinit...)
diff --git a/test/fixedbugs/issue56727.go b/test/fixedbugs/issue56727.go
new file mode 100644 (file)
index 0000000..af201c2
--- /dev/null
@@ -0,0 +1,45 @@
+// compile
+
+// 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 p
+
+type I interface {
+       M()
+}
+
+type S struct{}
+
+func (*S) M() {}
+
+type slice []I
+
+func f() {
+       ss := struct {
+               i I
+       }{
+               i: &S{},
+       }
+
+       _ = [...]struct {
+               s slice
+       }{
+               {
+                       s: slice{ss.i},
+               },
+               {
+                       s: slice{ss.i},
+               },
+               {
+                       s: slice{ss.i},
+               },
+               {
+                       s: slice{ss.i},
+               },
+               {
+                       s: slice{ss.i},
+               },
+       }
+}