Debian Codegraph @

go/analysis/passes/nilness/testdata/src/c/c.go

raw symbols SCIP
1 package c
2
3 func instantiated[X any](x *X) int {
4 if x == nil {
5 print(*x) // want "nil dereference in load"
6 }
7 return 1
8 }
9
10 var g int
11
12 func init() {
13 g = instantiated[int](&g)
14 }
15
16 // -- issue 66835 --
17
18 type Empty1 any
19 type Empty2 any
20
21 // T may be instantiated with an interface type, so any(x) may be nil.
22 func TypeParamInterface[T error](x T) {
23 if any(x) == nil {
24 print()
25 }
26 }
27
28 // T may not be instantiated with an interface type, so any(x) is non-nil
29 func TypeParamTypeSetWithInt[T interface {
30 error
31 int
32 }](x T) {
33 if any(x) == nil { // want "impossible condition: non-nil == nil"
34 print()
35 }
36 }
37
38 func TypeParamUnionEmptyEmpty[T Empty1 | Empty2](x T) {
39 if any(x) == nil {
40 print()
41 }
42 }
43
44 func TypeParamUnionEmptyInt[T Empty1 | int](x T) {
45 if any(x) == nil {
46 print()
47 }
48 }
49
50 func TypeParamUnionStringInt[T string | int](x T) {
51 if any(x) == nil { // want "impossible condition: non-nil == nil"
52 print()
53 }
54 }