blob: 1fc6e0a14ee533680f7c704b23d60551ab7d3f16 [file] [log] [blame]
Dan Willemsenbc60c3c2021-12-15 01:09:00 -08001// run -gcflags=-G=3
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
7package main
8
9type myint int
10func (x myint) foo() int {return int(x)}
11
12type myfloat float64
13func (x myfloat) foo() float64 {return float64(x) }
14
15func f[T any](i interface{}) {
16 switch x := i.(type) {
17 case interface { foo() T }:
18 println("fooer", x.foo())
19 default:
20 println("other")
21 }
22}
23func main() {
24 f[int](myint(6))
25 f[int](myfloat(7))
26 f[float64](myint(8))
27 f[float64](myfloat(9))
28}