Skip to content
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

assert,util: correct comparison when both contain same reference #53431

Merged
merged 2 commits into from
Jun 17, 2024

Conversation

lemire
Copy link
Member

@lemire lemire commented Jun 12, 2024

I would expect that given

const xarray = ['x'];

Then new Set([xarray, ['y']]) and new Set([xarray, ['y']]) are equal as per assert.deepStrictEqual but since Node 20, they are not.

This PR applies the fix proposed by @BridgeAR

Refs: #53423 reported by @chharvey

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test Issues and PRs related to the tests. labels Jun 12, 2024
@lemire lemire added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 12, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 12, 2024
@nodejs-github-bot
Copy link
Collaborator

@lemire
Copy link
Member Author

lemire commented Jun 12, 2024

@BridgeAR @mcollina @anonrig

Many changes were introduced in #46593 comparison.js but it looks to me like the new code has bugs, as reported by @chharvey.

@lemire lemire requested a review from anonrig June 12, 2024 20:29
@aduh95
Copy link
Contributor

aduh95 commented Jun 13, 2024

Can you fix the commit message? The subsystem should be test:, and it should be descriptive of what the change is – and the test should be added to known_issues given the test doesn't pass.

@mcollina
Copy link
Member

One year has passed since #46593. Should we revert? @BridgeAR @lemire would you be able to work a fix?

Co-authored-by: Chris Harvey <1362083+chharvey@users.noreply.github.com>
@lemire lemire changed the title assert: verify issue 53423 assert,util: correct comparison when both contain same reference Jun 13, 2024
@lemire lemire added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 13, 2024
@lemire
Copy link
Member Author

lemire commented Jun 13, 2024

@aduh95 Message reworded.

@lemire
Copy link
Member Author

lemire commented Jun 13, 2024

@mcollina In the issue, @BridgeAR proposed a fix which I have applied here.

@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 13, 2024
@@ -502,7 +502,7 @@ function setEquiv(a, b, strict, memo) {
for (const val of b) {
// Primitive values have already been handled above.
if (typeof val === 'object' && val !== null) {
if (!setHasEqualElement(set, val, strict, memo))
if (!a.has(val) && !setHasEqualElement(set, val, strict, memo))
return false;
} else if (!strict &&

This comment was marked as resolved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which if are you matching with which else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else will be reached as it's the inner if. It could be optimized code wise (there is some duplication that can be prevented), but that could also be done in a later PR to check what implementation is best.

Copy link
Contributor

@chharvey chharvey Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lemire Oops, my bad, I was matching the else on line 507 with the wrong if, the one on line 505. Indentation is hard 😜

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

Co-authored-by: James M Snell <jasnell@gmail.com>
@lpinca lpinca added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 14, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 14, 2024
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@lemire lemire added the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 17, 2024
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Jun 17, 2024
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/53431
✔  Done loading data for nodejs/node/pull/53431
----------------------------------- PR info ------------------------------------
Title      assert,util: correct comparison when both contain same reference  (#53431)
Author     Daniel Lemire  (@lemire)
Branch     lemire:verify_53423 -> nodejs:main
Labels     test, needs-ci
Commits    2
 - assert,util: correct comparison when both contain same reference
 - Update lib/internal/util/comparisons.js
Committers 2
 - Daniel Lemire 
 - GitHub 
PR-URL: https://github.com/nodejs/node/pull/53431
Refs: https://github.com/nodejs/node/issues/53423
Reviewed-By: Matteo Collina 
Reviewed-By: James M Snell 
Reviewed-By: Ruben Bridgewater 
Reviewed-By: Moshe Atlow 
Reviewed-By: Yagiz Nizipli 
Reviewed-By: Luigi Pinca 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/53431
Refs: https://github.com/nodejs/node/issues/53423
Reviewed-By: Matteo Collina 
Reviewed-By: James M Snell 
Reviewed-By: Ruben Bridgewater 
Reviewed-By: Moshe Atlow 
Reviewed-By: Yagiz Nizipli 
Reviewed-By: Luigi Pinca 
--------------------------------------------------------------------------------
   ℹ  This PR was created on Wed, 12 Jun 2024 15:04:11 GMT
   ✔  Approvals: 6
   ✔  - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/53431#pullrequestreview-2116256581
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/53431#pullrequestreview-2116361323
   ✔  - Ruben Bridgewater (@BridgeAR) (TSC): https://github.com/nodejs/node/pull/53431#pullrequestreview-2116501755
   ✔  - Moshe Atlow (@MoLow) (TSC): https://github.com/nodejs/node/pull/53431#pullrequestreview-2117085211
   ✔  - Yagiz Nizipli (@anonrig): https://github.com/nodejs/node/pull/53431#pullrequestreview-2117118245
   ✔  - Luigi Pinca (@lpinca): https://github.com/nodejs/node/pull/53431#pullrequestreview-2119125467
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2024-06-17T08:10:36Z: https://ci.nodejs.org/job/node-test-pull-request/59827/
- Querying data for job/node-test-pull-request/59827/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  No git cherry-pick in progress
   ✔  No git am in progress
   ✔  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
✔  origin/main is now up-to-date
- Downloading patch for 53431
From https://github.com/nodejs/node
 * branch                  refs/pull/53431/merge -> FETCH_HEAD
✔  Fetched commits as 2333573f3907..09449e7e728b
--------------------------------------------------------------------------------
[main bf3d689d2c] assert,util: correct comparison when both contain same reference
 Author: Daniel Lemire 
 Date: Wed Jun 12 11:00:46 2024 -0400
 2 files changed, 6 insertions(+), 2 deletions(-)
[main 2edda489f0] Update lib/internal/util/comparisons.js
 Author: Daniel Lemire 
 Date: Fri Jun 14 09:57:10 2024 -0400
 1 file changed, 2 insertions(+), 1 deletion(-)
   ✔  Patches applied
There are 2 commits in the PR. Attempting autorebase.
Rebasing (2/4)

Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
assert,util: correct comparison when both contain same reference

Co-authored-by: Chris Harvey 1362083+chharvey@users.noreply.github.com
PR-URL: #53431
Refs: #53423
Reviewed-By: Matteo Collina matteo.collina@gmail.com
Reviewed-By: James M Snell jasnell@gmail.com
Reviewed-By: Ruben Bridgewater ruben@bridgewater.de
Reviewed-By: Moshe Atlow moshe@atlow.co.il
Reviewed-By: Yagiz Nizipli yagiz.nizipli@sentry.io
Reviewed-By: Luigi Pinca luigipinca@gmail.com

[detached HEAD c7b2ebd1fe] assert,util: correct comparison when both contain same reference
Author: Daniel Lemire daniel@lemire.me
Date: Wed Jun 12 11:00:46 2024 -0400
2 files changed, 6 insertions(+), 2 deletions(-)
Rebasing (3/4)
Rebasing (4/4)

Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
Update lib/internal/util/comparisons.js

Co-authored-by: James M Snell jasnell@gmail.com
PR-URL: #53431
Refs: #53423
Reviewed-By: Matteo Collina matteo.collina@gmail.com
Reviewed-By: James M Snell jasnell@gmail.com
Reviewed-By: Ruben Bridgewater ruben@bridgewater.de
Reviewed-By: Moshe Atlow moshe@atlow.co.il
Reviewed-By: Yagiz Nizipli yagiz.nizipli@sentry.io
Reviewed-By: Luigi Pinca luigipinca@gmail.com

[detached HEAD d0c65e9521] Update lib/internal/util/comparisons.js
Author: Daniel Lemire daniel@lemire.me
Date: Fri Jun 14 09:57:10 2024 -0400
1 file changed, 2 insertions(+), 1 deletion(-)

Successfully rebased and updated refs/heads/main.

ℹ Add commit-queue-squash label to land the PR as one commit, or commit-queue-rebase to land as separate commits.

https://github.com/nodejs/node/actions/runs/9548251230

@lemire lemire added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Jun 17, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 17, 2024
@nodejs-github-bot nodejs-github-bot merged commit ee5c6b6 into nodejs:main Jun 17, 2024
66 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in ee5c6b6

targos pushed a commit that referenced this pull request Jun 20, 2024
Co-authored-by: Chris Harvey <1362083+chharvey@users.noreply.github.com>
PR-URL: #53431
Refs: #53423
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
sophonieb pushed a commit to sophonieb/node that referenced this pull request Jun 20, 2024
Co-authored-by: Chris Harvey <1362083+chharvey@users.noreply.github.com>
PR-URL: nodejs#53431
Refs: nodejs#53423
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
bmeck pushed a commit to bmeck/node that referenced this pull request Jun 22, 2024
Co-authored-by: Chris Harvey <1362083+chharvey@users.noreply.github.com>
PR-URL: nodejs#53431
Refs: nodejs#53423
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
@chharvey
Copy link
Contributor

@targos this seems like a critical bug fix… shouldn’t it go in an LTS version, v20?

marco-ippolito pushed a commit that referenced this pull request Jul 19, 2024
Co-authored-by: Chris Harvey <1362083+chharvey@users.noreply.github.com>
PR-URL: #53431
Refs: #53423
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
marco-ippolito pushed a commit that referenced this pull request Jul 19, 2024
Co-authored-by: Chris Harvey <1362083+chharvey@users.noreply.github.com>
PR-URL: #53431
Refs: #53423
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
@chharvey
Copy link
Contributor

chharvey commented Aug 4, 2024

responding to my own comment above … this is in LTS v20 as per 20.16 changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deepStrictEqual fails for Sets that contain both object references and equivalent object values
10 participants