Source file
test/typeparam/typeswitch1.go
1
2
3
4
5
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 case int32, int16:
16 println("int32/int16")
17 case struct{ a, b T }:
18 println("struct{T,T}")
19 default:
20 println("other")
21 }
22 }
23 func main() {
24 f[float64](float64(6))
25 f[float64](int(7))
26 f[float64](int32(8))
27 f[float64](struct{ a, b float64 }{a: 1, b: 2})
28 f[float64](int8(9))
29 f[int32](int32(7))
30 f[int](int32(7))
31 f[any](int(10))
32 f[interface{ M() }](int(11))
33 }
34
View as plain text