Source file test/typeparam/mdempsky/20.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 method expressions with a derived receiver type and
     8  // promoted methods work correctly.
     9  
    10  package main
    11  
    12  func main() {
    13  	F[int]()
    14  	F[string]()
    15  }
    16  
    17  func F[X any]() {
    18  	call(T[X].M, T[X].N)
    19  }
    20  
    21  func call[X any](fns ...func(T[X]) int) {
    22  	for want, fn := range fns {
    23  		if have := fn(T[X]{}); have != want {
    24  			println("FAIL:", have, "!=", want)
    25  		}
    26  	}
    27  }
    28  
    29  type T[X any] struct {
    30  	E1
    31  	*E2[*X]
    32  }
    33  
    34  type E1 struct{}
    35  type E2[_ any] struct{}
    36  
    37  func (E1) M() int     { return 0 }
    38  func (*E2[_]) N() int { return 1 }
    39  

View as plain text