diff --git a/src/cmd/compile/internal/gc/sinit.go b/src/cmd/compile/internal/gc/sinit.go index 92cf51e345..aa0c06c564 100644 --- a/src/cmd/compile/internal/gc/sinit.go +++ b/src/cmd/compile/internal/gc/sinit.go @@ -650,8 +650,6 @@ func getdyn(n *Node, top bool) initGenType { // isStaticCompositeLiteral reports whether n is a compile-time constant. func isStaticCompositeLiteral(n *Node) bool { switch n.Op { - case ONAME: - return n.Class() == PEXTERN && n.Name != nil && n.Name.Readonly() case OSLICELIT: return false case OARRAYLIT: diff --git a/test/fixedbugs/issue31782.go b/test/fixedbugs/issue31782.go new file mode 100644 index 0000000000..a42001ea0e --- /dev/null +++ b/test/fixedbugs/issue31782.go @@ -0,0 +1,24 @@ +// run + +// Copyright 2019 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. + +// Check static composite literal reports wrong for struct +// field. + +package main + +type one struct { + i interface{} +} + +type two struct { + i interface{} + s []string +} + +func main() { + o := one{i: two{i: 42}.i} + println(o.i.(int)) +} diff --git a/test/fixedbugs/issue31782.out b/test/fixedbugs/issue31782.out new file mode 100644 index 0000000000..d81cc0710e --- /dev/null +++ b/test/fixedbugs/issue31782.out @@ -0,0 +1 @@ +42