Skip to content

Commit

Permalink
cmd/compile: fix assert condition in generic method call
Browse files Browse the repository at this point in the history
Fixes golang#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]>
  • Loading branch information
wdvxdr1123 authored and gopherbot committed Jun 22, 2022
1 parent 6bad7e8 commit 4045b1b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/cmd/compile/internal/noder/stencil.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,15 @@ func (g *genInst) scanForGenCalls(decl ir.Node) {

st := g.getInstantiation(gf, targs, true).fun
dictValue, usingSubdict := g.getDictOrSubdict(declInfo, n, gf, targs, true)
// We have to be using a subdictionary, since this is
// a generic method call.
assert(usingSubdict)
if hasShapeTypes(targs) {
// We have to be using a subdictionary, since this is
// a generic method call.
assert(usingSubdict)
} else {
// We should use main dictionary, because the receiver is
// an instantiation already, see issue #53406.
assert(!usingSubdict)
}

// Transform to a function call, by appending the
// dictionary and the receiver to the args.
Expand Down
22 changes: 22 additions & 0 deletions test/typeparam/issue53406.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// compile

// 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[int]()
}

func f[T1 any]() {
var x Outer[T1, int]
x.M()
}

type Outer[T1, T2 any] struct{ Inner[T2] }

type Inner[_ any] int

func (Inner[_]) M() {}

0 comments on commit 4045b1b

Please sign in to comment.