]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/walk: fix wrong soleComponent implementation
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 30 Mar 2022 01:55:22 +0000 (08:55 +0700)
committerMichael Pratt <mpratt@google.com>
Wed, 30 Mar 2022 15:06:59 +0000 (15:06 +0000)
CL 367755 added soleComponent for handling 1-byte type interface conversion.
This implementation must be kept in sync with Type.SoleComponent, but it
does not. When seeing a blank field in struct, we must continue looking
at the field type to find sole component, if any. The current code just
terminate immediately, which causes wrong sole component type returned.

Fixes #52020

Change-Id: I4f506fe094fa7c5532de23467a4f9139476bb0a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/396614
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/walk/convert.go
test/fixedbugs/issue52020.go [new file with mode: 0644]

index 6edff4fbba607d3f59a86a2db997400d7021f9e0..72631e7dfb04e64375a54e2d107e0f15bd1b7d6d 100644 (file)
@@ -411,7 +411,7 @@ func soleComponent(init *ir.Nodes, n ir.Node) ir.Node {
                                // Treat blank fields as the zero value as the Go language requires.
                                n = typecheck.Temp(n.Type().Field(0).Type)
                                appendWalkStmt(init, ir.NewAssignStmt(base.Pos, n, nil))
-                               return n
+                               continue
                        }
                        n = typecheck.Expr(ir.NewSelectorExpr(n.Pos(), ir.OXDOT, n, n.Type().Field(0).Sym))
                case n.Type().IsArray():
diff --git a/test/fixedbugs/issue52020.go b/test/fixedbugs/issue52020.go
new file mode 100644 (file)
index 0000000..0d18b1f
--- /dev/null
@@ -0,0 +1,11 @@
+// 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 main
+
+func main() {
+       var _ interface{} = struct{ _ [1]int8 }{}
+}