-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deepStrictEqual
fails for Sets that contain both object references and equivalent object values
#53423
Comments
I have verified that the issue does not occur with Node 18 and yet it occurs systematically with Node 20 and up. |
it seems like it has somthing to do with x being an array saved in constant. example:
but:
can i work on this? |
Yes!!! Have a look at #53431 |
@DanielBelz1997 Yup, your analysis is correct. Take a look at the Starting on line 447, a new "SafeSet" is created that contains all the values in The bug lies on line 468, where we loop over the values in |
@chharvey thank you for the direction! I will get on that as soon as possible. |
This is a great catch! The bug seems to only occur for sets where both contain a reference identical object and another non-reference identical object. To fix it, it should be enough to add a check here to verify the reference identical one does not exist in the other set node/lib/internal/util/comparisons.js Line 505 in 1839eb2
if (!a.has(val) && !setHasEqualElement(set, val, strict, memo)) An alternative would be to undo some of the set changes from #46593. It was not an issue before due to always adding all objects to the intermediate set. I would just run the benchmark on both options and see what has less impact. |
Co-authored-by: Chris Harvey <[email protected]> PR-URL: #53431 Refs: #53423 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Co-authored-by: Chris Harvey <[email protected]> PR-URL: #53431 Refs: #53423 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Co-authored-by: Chris Harvey <[email protected]> PR-URL: nodejs#53431 Refs: nodejs#53423 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Co-authored-by: Chris Harvey <[email protected]> PR-URL: nodejs#53431 Refs: nodejs#53423 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Co-authored-by: Chris Harvey <[email protected]> PR-URL: #53431 Refs: #53423 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Co-authored-by: Chris Harvey <[email protected]> PR-URL: #53431 Refs: #53423 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Inspired by nodejs/node#53423. Already works here, but might as well cover it going forward.
Version
v20.0.0
Platform
Darwin MacBookPro2019.local 22.6.0 Darwin Kernel Version 22.6.0: Wed Oct 4 21:25:26 PDT 2023; root:xnu-8796.141.3.701.17~4/RELEASE_X86_64 x86_64
Subsystem
No response
What steps will reproduce the bug?
Run the following JavaScript in Node v20:
An AssertionError is reported, which is unexpected.
How often does it reproduce? Is there a required condition?
It is reproducible 100% of the time. It is not reproducible in v18.20.2, but reproducible starting in v20. No required condition.
What is the expected behavior? Why is that the expected behavior?
The expected behavior is that the assertion should pass. Both sets contain a reference to
x
(reference-equal) and also a new object['y']
(deep-equal), so the sets should be deeply equal.What do you see instead?
An assertion error is reported:
Additional information
The bug occurs only when comparing
Set
objects, with a mix of elements where some elements are objects compared by reference (===) and other elements are objects compared by deep equality.I believe it was introduced by #46593. Looking at the changed code, a new "SafeSet" is created only containing the values (of type
'object'
) ina
that are not inb
. So this SafeSet only contains['y']
. But then on line 468 of comparisons.js,for (const val of b)
, every value ofb
is checked, including the referencex
, which causes the failure because the SafeSet does not contain it.The text was updated successfully, but these errors were encountered: