From eb839b45b1da29038500ee6ae52526cbc854c6a1 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Sat, 20 Jun 2026 21:32:49 +0200 Subject: assert: fix crash in ErrEqual on expected being a struct kind value --- assert/errequal_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'assert/errequal_test.go') diff --git a/assert/errequal_test.go b/assert/errequal_test.go index 5efbdc5..4bb9080 100644 --- a/assert/errequal_test.go +++ b/assert/errequal_test.go @@ -74,4 +74,18 @@ func TestErrEqual(t *testing.T) { Outcome: testcapture.OutcomePanicked, Panic: "cannot handle `expected` of type int", }) + + // an earlier version had a bug because this call caused reflect.Value.IsNil() to be called on a value of kind Struct + expectErrors(t, func(t assert.TestingTB) { + assert.ErrEqual(t, nil, structTypedError{"foo"}) + }, `expected "foo", but got no error`) +} + +type structTypedError struct { + Message string +} + +// Error implements the builtin/error interface. +func (e structTypedError) Error() string { + return e.Message } -- cgit v1.3.1