From 2d34af0fd6c6cb214c3a5a8f11ef95854667dd92 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Wed, 30 Mar 2022 08:55:22 +0700 Subject: [PATCH] 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 Run-TryBot: Cuong Manh Le TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/walk/convert.go | 2 +- test/fixedbugs/issue52020.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue52020.go diff --git a/src/cmd/compile/internal/walk/convert.go b/src/cmd/compile/internal/walk/convert.go index 6edff4fbba..72631e7dfb 100644 --- a/src/cmd/compile/internal/walk/convert.go +++ b/src/cmd/compile/internal/walk/convert.go @@ -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 index 0000000000..0d18b1f7ae --- /dev/null +++ b/test/fixedbugs/issue52020.go @@ -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 }{} +} -- 2.50.0