Skip to content

IsNotNil() predicate is too strict #20

@maargenton

Description

@maargenton
var _, err = base64.RawURLEncoding.DecodeString("SGVsbG8gV29ybGQK@")
verify.That(t, err).IsNotNil()

Current output:

expected: value is not nil
error:    value of type 'base64.CorruptInputError' can never be nil
value:    16

Because base64.CorruptInputError is a non-nillable int64 derived type that implements the error interface and returned as an error type by DecodeString(), it should be testable with .IsNil() / .IsNotNil() and be considered not nil. Instead, .IsNotNil() flags this as a programming error because of the underlying type.

Expected behavior:

.IsNotNil(), commonly used for testing that a non-specific error is returned, should pass for any value of a non-nillable types, like numbers and strings.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinginvalidThis doesn't seem right

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions