Skip to content

Commit 2b748f0

Browse files
committed
[dev.go2go] cmd/compile/internal/types2: fix instantiation crash for generic type parameters
Port of go/types CL https://golang.org/cl/247498. Updates #40038. Change-Id: Iab002132627b689e0113c087b3f4d38c6356c3a3 Reviewed-on: https://go-review.googlesource.com/c/go/+/248058 Reviewed-by: Robert Griesemer <[email protected]>
1 parent fc29b90 commit 2b748f0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2020 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
type A[type T] int
8+
9+
func (A[T]) m(A[T])
10+
11+
func f[type P interface{m(P)}]()
12+
13+
func _() {
14+
_ = f[A]
15+
}

src/cmd/compile/internal/types2/lookup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ func (check *Checker) missingMethod(V Type, T *Interface, static bool) (method,
394394
// In order to compare the signatures, substitute the receiver
395395
// type parameters of ftyp with V's instantiation type arguments.
396396
// This lazily instantiates the signature of method f.
397-
if Vn != nil && len(Vn.targs) > 0 {
397+
if Vn != nil && len(Vn.tparams) > 0 {
398398
// Be careful: The number of type arguments may not match
399399
// the number of receiver parameters. If so, an error was
400400
// reported earlier but the length discrepancy is still

0 commit comments

Comments
 (0)