Source file src/internal/types/testdata/fixedbugs/issue60562.go

     1  // Copyright 2023 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 S[T any] struct{}
     8  
     9  func (S[T]) m(T) {}
    10  
    11  func f0[T any](chan S[T]) {}
    12  
    13  func _() {
    14  	var x chan interface{ m(int) }
    15  	f0(x /* ERROR "type chan interface{m(int)} of x does not match chan S[T] (cannot infer T)" */)
    16  }
    17  
    18  // variants of the theme
    19  
    20  func f1[T any]([]S[T]) {}
    21  
    22  func _() {
    23  	var x []interface{ m(int) }
    24  	f1(x /* ERROR "type []interface{m(int)} of x does not match []S[T] (cannot infer T)" */)
    25  }
    26  
    27  type I[T any] interface {
    28  	m(T)
    29  }
    30  
    31  func f2[T any](func(I[T])) {}
    32  
    33  func _() {
    34  	var x func(interface{ m(int) })
    35  	f2(x /* ERROR "type func(interface{m(int)}) of x does not match func(I[T]) (cannot infer T)" */)
    36  }
    37  
    38  func f3[T any](func(I[T])) {}
    39  
    40  func _() {
    41  	var x func(I[int])
    42  	f3(x) // but this is correct: I[T] and I[int] can be made identical with T == int
    43  }
    44  
    45  func f4[T any]([10]I[T]) {}
    46  
    47  func _() {
    48  	var x [10]interface{ I[int] }
    49  	f4(x /* ERROR "type [10]interface{I[int]} of x does not match [10]I[T] (cannot infer T)" */)
    50  }
    51  
    52  func f5[T any](I[T]) {}
    53  
    54  func _() {
    55  	var x interface {
    56  		m(int)
    57  		n()
    58  	}
    59  	f5(x)
    60  	f5[int](x) // ok
    61  }
    62  

View as plain text