Debian Codegraph @

staticcheck/sa1012/testdata/go1.0/checkStdlibUsageNilContext/checkStdlibUsageNilContext.go.golden

raw
1 -- Use context.Background --
2 package pkg
3
4 import "context"
5
6 func fn1(ctx context.Context) {}
7 func fn2(x string, ctx context.Context) {}
8 func fn4() {}
9
10 type T struct{}
11
12 func (*T) Foo() {}
13
14 func fn3() {
15 fn1(context.Background()) //@ diag(`do not pass a nil Context`)
16 fn1(context.TODO())
17 fn2("", nil)
18 fn4()
19
20 // don't flag this conversion
21 _ = (func(context.Context))(nil)
22 // and don't crash on these
23 _ = (func())(nil)
24 (*T).Foo(nil)
25 }
26 -- Use context.TODO --
27 package pkg
28
29 import "context"
30
31 func fn1(ctx context.Context) {}
32 func fn2(x string, ctx context.Context) {}
33 func fn4() {}
34
35 type T struct{}
36
37 func (*T) Foo() {}
38
39 func fn3() {
40 fn1(context.TODO()) //@ diag(`do not pass a nil Context`)
41 fn1(context.TODO())
42 fn2("", nil)
43 fn4()
44
45 // don't flag this conversion
46 _ = (func(context.Context))(nil)
47 // and don't crash on these
48 _ = (func())(nil)
49 (*T).Foo(nil)
50 }