1
2
3
4
5 package a
6
7 type IVal[T comparable] interface {
8 check(want T)
9 }
10
11 type Val[T comparable] struct {
12 val T
13 }
14
15
16 func (l *Val[T]) check(want T) {
17 if l.val != want {
18 panic("hi")
19 }
20 }
21
22 func Test1() {
23 var l Val[int]
24 if l.val != 0 {
25 panic("hi")
26 }
27 _ = IVal[int](&l)
28 }
29
30 func Test2() {
31 var l Val[float64]
32 l.val = 3.0
33 l.check(float64(3))
34 _ = IVal[float64](&l)
35 }
36
37 type privateVal[T comparable] struct {
38 val T
39 }
40
41
42 func (l *privateVal[T]) check(want T) {
43 if l.val != want {
44 panic("hi")
45 }
46 }
47
48 type Outer struct {
49 val privateVal[string]
50 }
51
52 func Test3() {
53 var o Outer
54 o.val.check("")
55 _ = IVal[string](&o.val)
56 }
57
View as plain text