Source file test/typeparam/issue51522a.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  package main
     7  
     8  
     9  func f[T comparable](i any) {
    10  	var t T
    11  
    12  	if i != t {
    13  		println("FAIL: if i != t")
    14  	}
    15  }
    16  
    17  type myint int
    18  
    19  func (m myint) foo() {
    20  }
    21  
    22  type fooer interface {
    23  	foo()
    24  }
    25  
    26  type comparableFoo interface {
    27  	comparable
    28  	foo()
    29  }
    30  
    31  func g[T comparableFoo](i fooer) {
    32  	var t T
    33  
    34  	if i != t {
    35  		println("FAIL: if i != t")
    36  	}
    37  }
    38  
    39  func main() {
    40  	f[int](int(0))
    41  	g[myint](myint(0))
    42  }
    43  

View as plain text