Source file
test/typeparam/issue50642.go
1
2
3
4
5
6
7 package main
8
9 import "fmt"
10
11 type Temp[T any] struct {
12 }
13
14 var temp, temp1 any
15 var ch any
16
17 func (it Temp[T]) HasNext() bool {
18 var ok bool
19 temp1 = <-ch.(chan T)
20
21 temp, ok = <-ch.(chan T)
22 return ok
23 }
24
25 type MyInt int
26
27 func (i MyInt) String() string {
28 return "a"
29 }
30
31 type Stringer interface {
32 String() string
33 }
34
35 type Temp2[T Stringer] struct {
36 }
37
38 var temp2 Stringer
39
40 func (it Temp2[T]) HasNext() string {
41 var x map[int]T
42
43 var ok bool
44
45 temp2, ok = x[43]
46 _ = ok
47 return temp2.String()
48 }
49
50 func main() {
51 ch1 := make(chan int, 2)
52 ch1 <- 5
53 ch1 <- 6
54 ch = ch1
55 iter := Temp[int]{}
56 iter.HasNext()
57
58 iter2 := Temp2[MyInt]{}
59 if got, want := iter2.HasNext(), "a"; got != want {
60 panic(fmt.Sprintf("got %v, want %v", got, want))
61 }
62
63 }
64
View as plain text