diff options
author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2022-11-14 23:11:30 +0700 |
---|---|---|
committer | Michael Pratt <mpratt@google.com> | 2022-12-09 21:06:32 +0000 |
commit | 926ffba40bb44ef931d4b7397bd381b417cbbc9b (patch) | |
tree | 62d5661625df2838a7302760b4a3c87174325dc7 | |
parent | 1b4db7e46365bbbba479d0689c5699e6c0ba1142 (diff) | |
download | go-926ffba40bb44ef931d4b7397bd381b417cbbc9b.tar.gz go-926ffba40bb44ef931d4b7397bd381b417cbbc9b.zip |
[release-branch.go1.19] cmd/compile: fix missing typecheck for static initialization slice
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>
-rw-r--r-- | src/cmd/compile/internal/walk/complit.go | 1 | ||||
-rw-r--r-- | test/fixedbugs/issue56727.go | 45 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/walk/complit.go b/src/cmd/compile/internal/walk/complit.go index 603c479a08..71ab4700e0 100644 --- a/src/cmd/compile/internal/walk/complit.go +++ b/src/cmd/compile/internal/walk/complit.go @@ -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 index 0000000000..af201c22a8 --- /dev/null +++ b/test/fixedbugs/issue56727.go @@ -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}, + }, + } +} |