Skip to content

Commit 4045b1b

Browse files
wdvxdr1123gopherbot
authored andcommitted
cmd/compile: fix assert condition in generic method call
Fixes #53406. Change-Id: If7ae39ec1042a792d82a0a2de96d168c22d8ab71 Reviewed-on: https://go-review.googlesource.com/c/go/+/412614 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Alex Rakoczy <[email protected]> Auto-Submit: Alex Rakoczy <[email protected]> Reviewed-by: Keith Randall <[email protected]> Run-TryBot: Wayne Zuo <[email protected]>
1 parent 6bad7e8 commit 4045b1b

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,15 @@ func (g *genInst) scanForGenCalls(decl ir.Node) {
208208

209209
st := g.getInstantiation(gf, targs, true).fun
210210
dictValue, usingSubdict := g.getDictOrSubdict(declInfo, n, gf, targs, true)
211-
// We have to be using a subdictionary, since this is
212-
// a generic method call.
213-
assert(usingSubdict)
211+
if hasShapeTypes(targs) {
212+
// We have to be using a subdictionary, since this is
213+
// a generic method call.
214+
assert(usingSubdict)
215+
} else {
216+
// We should use main dictionary, because the receiver is
217+
// an instantiation already, see issue #53406.
218+
assert(!usingSubdict)
219+
}
214220

215221
// Transform to a function call, by appending the
216222
// dictionary and the receiver to the args.

test/typeparam/issue53406.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// compile
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+
func main() {
10+
f[int]()
11+
}
12+
13+
func f[T1 any]() {
14+
var x Outer[T1, int]
15+
x.M()
16+
}
17+
18+
type Outer[T1, T2 any] struct{ Inner[T2] }
19+
20+
type Inner[_ any] int
21+
22+
func (Inner[_]) M() {}

0 commit comments

Comments
 (0)