mirror of
https://github.com/golang/go
synced 2024-09-05 16:04:50 +00:00
![Matthew Dempsky](/assets/img/avatar_default.png)
When types2 type checks a method expression or method value that selects a type parameter method, the Selection.Index is indexed based on the method's index within the type parameter's constraint interface. However, with a fully-stenciled implementation, naively using the index would result in picking a method from the corresponding type argument's full method set, which could select a different method. Unified IR currently avoids this because it selects methods based on name, not index; but experimenting with index-based selection revealed that there are no test cases that would have caught this failure case. Change-Id: Idbc39e1ee741714203d4749e47f5bc015af25020 Reviewed-on: https://go-review.googlesource.com/c/go/+/421815 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: David Chase <drchase@google.com>
33 lines
662 B
Go
33 lines
662 B
Go
// run
|
|
|
|
// 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.
|
|
|
|
// Test that type parameter methods are handled correctly, even when
|
|
// the instantiating type argument has additional methods.
|
|
|
|
package main
|
|
|
|
func main() {
|
|
F(X(0))
|
|
}
|
|
|
|
type I interface{ B() }
|
|
|
|
func F[T I](t T) {
|
|
CallMethod(t)
|
|
MethodExpr[T]()(t)
|
|
MethodVal(t)()
|
|
}
|
|
|
|
func CallMethod[T I](t T) { t.B() }
|
|
func MethodExpr[T I]() func(T) { return T.B }
|
|
func MethodVal[T I](t T) func() { return t.B }
|
|
|
|
type X int
|
|
|
|
func (X) A() { panic("FAIL") }
|
|
func (X) B() {}
|
|
func (X) C() { panic("FAIL") }
|