Source file
test/fixedbugs/issue71252.go
1
2
3
4
5
6
7
8
9
10
11
12 package main
13
14 import "fmt"
15
16 func peek[V any](v V) (V, bool) { return v, true }
17
18 type Cache[V any] struct{ v V }
19
20 func (c *Cache[V]) Peek() (V, bool) { return c.v, true }
21
22 type Rec struct{ Data []byte }
23
24 func main() {
25
26 blk, _ := peek(new([4096]byte))
27 if got := len(blk[:]); got != 4096 {
28 panic(fmt.Sprintf("len(blk[:]) = %d, want 4096", got))
29 }
30
31
32 c := &Cache[*[2048]byte]{v: new([2048]byte)}
33 blk2, _ := c.Peek()
34 if got := len(blk2[:]); got != 2048 {
35 panic(fmt.Sprintf("len(blk2[:]) = %d, want 2048", got))
36 }
37
38
39 blk3, _ := peek(new([1024]byte))
40 if got := len(Rec{Data: blk3[:]}.Data); got != 1024 {
41 panic(fmt.Sprintf("len(Rec{...}.Data) = %d, want 1024", got))
42 }
43 }
44
View as plain text