You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
I don't like 3. because I don't want to add dependencies to this library.
Another possible solution is to wait for the generics in go v1.18 and use that instead.
The PR is merged. Thank you for your contribution.
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:
(*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.reflect.ValueOf(a).IsNil()
(not recommended)The text was updated successfully, but these errors were encountered: