Skip to content

Commit 93aab18

Browse files
cuonglmheschi
authored andcommitted
[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 <[email protected]> Reviewed-by: David Chase <[email protected]> Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/go/+/416155 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
1 parent 3a7cec2 commit 93aab18

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/cmd/compile/internal/noder/stencil.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,12 +1599,14 @@ func (g *genInst) getDictionarySym(gf *ir.Name, targs []*types.Type, isMeth bool
15991599
se := call.X.(*ir.SelectorExpr)
16001600
if se.X.Type().IsShape() {
16011601
// This is a method call enabled by a type bound.
1602-
1603-
// We need this extra check for method expressions,
1604-
// which don't add in the implicit XDOTs.
1605-
tmpse := ir.NewSelectorExpr(src.NoXPos, ir.OXDOT, se.X, se.Sel)
1606-
tmpse = typecheck.AddImplicitDots(tmpse)
1607-
tparam := tmpse.X.Type()
1602+
tparam := se.X.Type()
1603+
if call.X.Op() == ir.ODOTMETH {
1604+
// We need this extra check for method expressions,
1605+
// which don't add in the implicit XDOTs.
1606+
tmpse := ir.NewSelectorExpr(src.NoXPos, ir.OXDOT, se.X, se.Sel)
1607+
tmpse = typecheck.AddImplicitDots(tmpse)
1608+
tparam = tmpse.X.Type()
1609+
}
16081610
if !tparam.IsShape() {
16091611
// The method expression is not
16101612
// really on a typeparam.

test/typeparam/issue53419.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// run -gcflags=-G=3
2+
3+
// Copyright 2022 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
type T1 struct{}
10+
type T2 struct{}
11+
type Both struct {
12+
T1
13+
T2
14+
}
15+
16+
func (T1) m() { panic("FAIL") }
17+
func (T2) m() { panic("FAIL") }
18+
func (Both) m() {}
19+
20+
func f[T interface{ m() }](c T) {
21+
c.m()
22+
}
23+
24+
func main() {
25+
var b Both
26+
b.m()
27+
f(b)
28+
}

0 commit comments

Comments
 (0)