cmd/compile/internal/walk: fix wrong soleComponent implementation

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>
This commit is contained in:
Cuong Manh Le 2022-03-30 08:55:22 +07:00 committed by Michael Pratt
parent f5a42cd4b4
commit 2d34af0fd6
2 changed files with 12 additions and 1 deletions

View 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():

View File

@ -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 }{}
}