Source file test/typeparam/mdempsky/19.go

     1  // run
     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  // Test that type parameter methods are handled correctly, even when
     8  // the instantiating type argument has additional methods.
     9  
    10  package main
    11  
    12  func main() {
    13  	F(X(0))
    14  }
    15  
    16  type I interface{ B() }
    17  
    18  func F[T I](t T) {
    19  	CallMethod(t)
    20  	MethodExpr[T]()(t)
    21  	MethodVal(t)()
    22  }
    23  
    24  func CallMethod[T I](t T)       { t.B() }
    25  func MethodExpr[T I]() func(T)  { return T.B }
    26  func MethodVal[T I](t T) func() { return t.B }
    27  
    28  type X int
    29  
    30  func (X) A() { panic("FAIL") }
    31  func (X) B() {}
    32  func (X) C() { panic("FAIL") }
    33  

View as plain text