Fix asymmetric none equality bug in Value::operator==#26
Open
ender672 wants to merge 1 commit intoochafik:mainfrom
Open
Fix asymmetric none equality bug in Value::operator==#26ender672 wants to merge 1 commit intoochafik:mainfrom
ender672 wants to merge 1 commit intoochafik:mainfrom
Conversation
When none is on the left side of `==`, the operator falls through to
comparing `primitive_` fields. Since arrays and objects leave `primitive_`
as the default `json(null)`, `none == []` and `none == {}` incorrectly
returned true while `[] == none` correctly returned false.
Add an early return when the other side has `array_` or `object_` set,
and add tests covering both directions of none-vs-container comparisons.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
none == []andnone == {}incorrectly returntrue, while[] == noneand{} == nonecorrectly returnfalse.When none is on the left side,
operator==falls through to comparingprimitive_fields. Since arrays and objects leaveprimitive_as the defaultjson(null), it matches none's primitive and returns true.Found while fuzzing minja and comparing to an experimental JS port.
Fix
Add an early return in the
elsebranch ofoperator==when the other side hasarray_orobject_set (1-line change inminja.hpp).Test plan
NoneEqualitytest case intest-syntax.cppcovering both directions of none-vs-container comparisons