Closed
Description
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:
- 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
- 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. - Use a popular third party library such as https://pkg.go.dev/github.com/google/go-cmp/cmp
- Use reflection
reflect.ValueOf(a).IsNil()
(not recommended)
Metadata
Metadata
Assignees
Labels
No labels