Skip to content

checkNilCase test helper function invalid logic #503

Closed
@cnnrrss

Description

@cnnrrss

During my work on issue 491 I noticed that the logic of the test helper function checkNilCase is invalid because the function arguments a and b will never be nil.

This is a common bug in go where an interface value that holds a nil value is itself non-nil. This is mentioned in the tour of go.

I created a simplified demonstration in the playground https://go.dev/play/p/lNyfmdEpOnE.

Possible solutions to this problem include:

  1. Remove the checkNilCase helper function. It's currently not doing anything so it would be safe to delete. If this is the desired approach, this PR could be merged: Fix remove checkNilCase test helper function #504
  2. Never use (*T)(nil) as an interface{}, and instead do the check before. This would mean duplicating the checkNilCase function logic into separate functions for any type that would need it.
  3. Use a popular third party library such as https://pkg.go.dev/github.com/google/go-cmp/cmp
  4. Use reflection reflect.ValueOf(a).IsNil() (not recommended)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions