fix: keep nil map values in EqualExportedValues - #1972
Open
januththedev wants to merge 1 commit into
Open
januththedev wants to merge 1 commit into
januththedev wants to merge 1 commit into
Conversation
januththedev
force-pushed
the
fix/equal-exported-values-nil-map
branch
from
October 3, 2026 10:38
683cf60 to
4d23052
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
EqualExportedValuesreported structurally different maps as equal when a map value was untypednil.In
copyExportedFields, thereflect.Mapcase did:For a
map[string]interface{}holding anilvalue,index.Interface()is an untypednil, socopyExportedFieldsreturns untypednil.reflect.ValueOf(nil)is the zeroreflect.Value, and per thereflectcontractSetMapIndextreats a zero Value as delete this key. The entry therefore vanished from the cleaned copy before the comparison ever ran.The consequence is the worst kind for an assertion library: the assertion passes when it should fail, silently turning a real test failure green.
Reproduction
with an empty failure message, while the non-nil control
map[string]interface{}{"a": 1}againstmap[string]interface{}{}correctly reports false — isolating the defect to nil values specifically.The change
Typed nils such as
map[string]*int{"a": nil}are unaffected — they compare!= nilas an interface and still take the original path. Only genuinely untyped nils, which previously disappeared, take the new one. TheStructcase already handled nil correctly by leaving the zero value in place, so this makes the two cases consistent.Tests
Expected EqualExportedValues to be false, but was true, and all pass after.go test -count=1 ./assert/ ./require/→ 593 and 116 tests, 0 failures.go build ./...andgo vet ./...clean; edited files aregofmt-clean.Note on the 12 failures in
./suite/: those are pre-existing panic/recover test failures on this Windows checkout. I confirmed they reproduce identically with my changes stashed on a clean tree, and they are in a different package.