Source file
test/fixedbugs/issue76744.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package main
16
17 type I interface{ bool | float64 }
18
19 type G[T I] interface{ Val() T }
20
21 type BoolLit bool
22
23 func (b BoolLit) Val() bool { return bool(b) }
24
25 type F64Lit float64
26
27 func (f F64Lit) Val() float64 { return float64(f) }
28
29 func newLit[T I](val T) any {
30 switch v := any(val).(type) {
31 case bool:
32 return BoolLit(v)
33 case float64:
34 return F64Lit(v)
35 }
36 panic("unreachable")
37 }
38
39 func f[T I]() T {
40 var z T
41 return newLit(z).(G[T]).Val()
42 }
43
44 func main() {
45 if got := f[bool](); got != false {
46 panic("unexpected result")
47 }
48 if got := f[float64](); got != 0 {
49 panic("unexpected result")
50 }
51 }
52
View as plain text