Debian Codegraph @

test/typeparam/issue50417b.go

raw
1 // run
2
3 // Copyright 2022 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
7 package main
8
9 func main() {}
10
11 // Field accesses through type parameters are disabled
12 // until we have a more thorough understanding of the
13 // implications on the spec. See issue #51576.
14
15 /*
16 import "fmt"
17
18 type MyStruct struct {
19 b1, b2 string
20 E
21 }
22
23 type E struct {
24 val int
25 }
26
27 type C interface {
28 ~struct {
29 b1, b2 string
30 E
31 }
32 }
33
34 func f[T C]() T {
35 var x T = T{
36 b1: "a",
37 b2: "b",
38 }
39
40 if got, want := x.b2, "b"; got != want {
41 panic(fmt.Sprintf("got %d, want %d", got, want))
42 }
43 x.b1 = "y"
44 x.val = 5
45
46 return x
47 }
48
49 func main() {
50 x := f[MyStruct]()
51 if got, want := x.b1, "y"; got != want {
52 panic(fmt.Sprintf("got %d, want %d", got, want))
53 }
54 if got, want := x.val, 5; got != want {
55 panic(fmt.Sprintf("got %d, want %d", got, want))
56 }
57 }
58 */