honnef.co/go/tools@v0.4.7/staticcheck/testdata/src/example.com/checkStdlibUsageNilContext/checkStdlibUsageNilContext.go (about)

     1  package pkg
     2  
     3  import "context"
     4  
     5  func fn1(ctx context.Context)           {}
     6  func fn2(x string, ctx context.Context) {}
     7  func fn4()                              {}
     8  
     9  type T struct{}
    10  
    11  func (*T) Foo() {}
    12  
    13  func fn3() {
    14  	fn1(nil) //@ diag(`do not pass a nil Context`)
    15  	fn1(context.TODO())
    16  	fn2("", nil)
    17  	fn4()
    18  
    19  	// don't flag this conversion
    20  	_ = (func(context.Context))(nil)
    21  	// and don't crash on these
    22  	_ = (func())(nil)
    23  	(*T).Foo(nil)
    24  }