diff options
author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2022-06-29 02:05:21 +0700 |
---|---|---|
committer | Heschi Kreinick <heschi@google.com> | 2022-07-07 17:30:11 +0000 |
commit | 93aab1813930fd3e936d13cb2d0729a8b60aa541 (patch) | |
tree | cd480fd6e7acac4643b1b6508ec101e0c59ee700 | |
parent | 3a7cec27738c51347f4e5a466410a0b2089391b7 (diff) | |
download | go-93aab1813930fd3e936d13cb2d0729a8b60aa541.tar.gz go-93aab1813930fd3e936d13cb2d0729a8b60aa541.zip |
[release-branch.go1.18] cmd/compile: only check implicit dots for method call enabled by a type bound
Fixes #53723
Change-Id: Ibad64f5c4af2112deeb0a9ecc9c589b17594bd05
Reviewed-on: https://go-review.googlesource.com/c/go/+/414836
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-on: https://go-review.googlesource.com/c/go/+/416155
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
-rw-r--r-- | src/cmd/compile/internal/noder/stencil.go | 14 | ||||
-rw-r--r-- | test/typeparam/issue53419.go | 28 |
2 files changed, 36 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index 4c3dd37d94..e89b69284c 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -1599,12 +1599,14 @@ func (g *genInst) getDictionarySym(gf *ir.Name, targs []*types.Type, isMeth bool se := call.X.(*ir.SelectorExpr) if se.X.Type().IsShape() { // 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) - tmpse = typecheck.AddImplicitDots(tmpse) - tparam := tmpse.X.Type() + tparam := se.X.Type() + if call.X.Op() == ir.ODOTMETH { + // 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) + tmpse = typecheck.AddImplicitDots(tmpse) + tparam = tmpse.X.Type() + } if !tparam.IsShape() { // The method expression is not // really on a typeparam. diff --git a/test/typeparam/issue53419.go b/test/typeparam/issue53419.go new file mode 100644 index 0000000000..0bef4a91a0 --- /dev/null +++ b/test/typeparam/issue53419.go @@ -0,0 +1,28 @@ +// run -gcflags=-G=3 + +// 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 + +type T1 struct{} +type T2 struct{} +type Both struct { + T1 + T2 +} + +func (T1) m() { panic("FAIL") } +func (T2) m() { panic("FAIL") } +func (Both) m() {} + +func f[T interface{ m() }](c T) { + c.m() +} + +func main() { + var b Both + b.m() + f(b) +} |