package customcontext
import (
"context"
"time"
)
var _ context.Context = &MyContext{}
func f1(ctx context.Context) {
passesContextTODO() // want "Function `passesContextTODO` should pass the context parameter"
passesMyContextTODO() // want "Function `passesMyContextTODO` should pass the context parameter"
}
func needsSTLCtx(ctx context.Context) {}
func needsCustomCtx(ctx *MyContext) {}
func passesContextTODO() {
needsSTLCtx(context.TODO())
}
func passesMyContextTODO() {
needsCustomCtx(&MyContext{})
}
// ------------------------------
type MyContext struct {
}
func (ctx *MyContext) Deadline() (time.Time, bool) {
return time.Now(), true
}
func (ctx *MyContext) Done() <-chan struct{} {
return make(chan struct{})
}
func (ctx *MyContext) Err() error {
return nil
}
func (ctx *MyContext) Value(_ any) any {
return nil
}
The following fails when I plug it into contextcheck’s test suite: