Skip to content

contextcheck doesn’t recognize Context implementations besides STL #20

@FGasper

Description

@FGasper

The following fails when I plug it into contextcheck’s test suite:

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions