From e99f285d52627aa415f9c1766cbffe375b2f67d9 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Tue, 9 Aug 2022 19:30:47 +0700 Subject: [PATCH] cmd/compile: fix ICE when checking implicit dot for method call CL 414836 limited the check for implicit dot for method call enabled by a type bound. However, the checking condition for ODOTMETH only is not right. For example, for promoted method, we have a OXDOT node instead, and we still have to check for implicit dot in this case. However, if the base type and embedded types have the same method name, e.g in issue #53419, typecheck.AddImplicitDots will be confused and result in an ambigus selector. To fix this, we ensure methods for the base type are computed, then only do the implicit dot check if we can find a matched method. Fixes #54348 Change-Id: Iefe84ff330830afe35c5daffd499824db108da23 Reviewed-on: https://go-review.googlesource.com/c/go/+/422274 TryBot-Result: Gopher Robot Reviewed-by: Keith Randall Reviewed-by: Matthew Dempsky Run-TryBot: Cuong Manh Le Auto-Submit: Keith Randall Reviewed-by: Keith Randall --- src/cmd/compile/internal/noder/stencil.go | 6 ++++-- test/fixedbugs/issue54348.go | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 test/fixedbugs/issue54348.go diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index 6fcb31b472..5a41d2f1f0 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -1656,9 +1656,11 @@ func (g *genInst) getDictionarySym(gf *ir.Name, targs []*types.Type, isMeth bool var nameNode *ir.Name se := call.X.(*ir.SelectorExpr) if se.X.Type().IsShape() { - // This is a method call enabled by a type bound. tparam := se.X.Type() - if call.X.Op() == ir.ODOTMETH { + // Ensure methods on all instantiating types are computed. + typecheck.CalcMethods(tparam) + if typecheck.Lookdot1(nil, se.Sel, tparam, tparam.AllMethods(), 0) != nil { + // This is a method call enabled by a type bound. // We need this extra check for method expressions, // which don't add in the implicit XDOTs. tmpse := ir.NewSelectorExpr(src.NoXPos, ir.OXDOT, se.X, se.Sel) diff --git a/test/fixedbugs/issue54348.go b/test/fixedbugs/issue54348.go new file mode 100644 index 0000000000..15b2f758ef --- /dev/null +++ b/test/fixedbugs/issue54348.go @@ -0,0 +1,22 @@ +// run + +// 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() { + F[T[int]]() +} + +func F[X interface{ M() }]() { + var x X + x.M() +} + +type T[X any] struct{ E } + +type E struct{} + +func (h E) M() {} -- 2.50.0