cmd/compile/internal/devirtualize: fix OCONVNOP assertion

Fixes #75863

Change-Id: I1e5a0f3880dcd5f820a5b6f4540c49b16a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/711141
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
Auto-Submit: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Mateusz Poliwczak 2025-10-12 11:15:11 +02:00
parent 3765758b96
commit 5a9ef44bc0
2 changed files with 7 additions and 1 deletions

View file

@ -223,7 +223,7 @@ func concreteType1(s *State, n ir.Node, seen map[*ir.Name]struct{}) (outT *types
switch n1 := n.(type) {
case *ir.ConvExpr:
if n1.Op() == ir.OCONVNOP {
if !n1.Type().IsInterface() || !types.Identical(n1.Type(), n1.X.Type()) {
if !n1.Type().IsInterface() || !types.Identical(n1.Type().Underlying(), n1.X.Type().Underlying()) {
// As we check (directly before this switch) whether n is an interface, thus we should only reach
// here for iface conversions where both operands are the same.
base.Fatalf("not identical/interface types found n1.Type = %v; n1.X.Type = %v", n1.Type(), n1.X.Type())

View file

@ -1139,6 +1139,12 @@ func devirtWrapperType() {
var a A = (implWrapper)(i) // ERROR "implWrapper\(i\) does not escape$"
a.A() // ERROR "devirtualizing a.A to implWrapper$" "inlining call to implWrapper.A"
}
{
type anyWrapper any
var foo any = &Impl{} // ERROR "&Impl\{\} does not escape"
var bar anyWrapper = foo
bar.(M).M() // ERROR "devirtualizing bar\.\(M\).M to \*Impl" "inlining call to \(\*Impl\)\.M"
}
}
func selfAssigns() {