Source file test/typeparam/typeswitch6.go

     1  // run
     2  
     3  // Copyright 2021 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  package main
     8  
     9  func f[T any](i interface{}) {
    10  	switch i.(type) {
    11  	case T:
    12  		println("T")
    13  	case int:
    14  		println("int")
    15  	default:
    16  		println("other")
    17  	}
    18  }
    19  
    20  type myint int
    21  func (myint) foo() {
    22  }
    23  
    24  func main() {
    25  	f[interface{}](nil)
    26  	f[interface{}](6)
    27  	f[interface{foo()}](nil)
    28  	f[interface{foo()}](7)
    29  	f[interface{foo()}](myint(8))
    30  }
    31  

View as plain text