Source file test/typeparam/issue53477.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 generic interface-interface comparisons resulting from
     8  // value switch statements are handled correctly.
     9  
    10  package main
    11  
    12  func main() {
    13  	f[X](0)
    14  }
    15  
    16  type Mer[T any] interface{ M(T) }
    17  type MNer[T any] interface {
    18  	Mer[T]
    19  	N()
    20  }
    21  
    22  type X int
    23  
    24  func (X) M(X) {}
    25  func (X) N()  {}
    26  
    27  func f[T MNer[T]](t T) {
    28  	switch Mer[T](t) {
    29  	case MNer[T](t):
    30  		// ok
    31  	default:
    32  		panic("FAIL")
    33  	}
    34  }
    35  

View as plain text