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

Fix comparaison between optional list when one is None #3618

Merged
merged 2 commits into from
Nov 28, 2023

Conversation

MangelMaxime
Copy link
Member

@MangelMaxime MangelMaxime commented Nov 28, 2023

Fix #3617

The error actually comes from:

CleanShot 2023-11-28 at 11 34 08@2x

Because the code expect xs_1 and ys_1 to be list. But because the def equal in util.py doesn't capture the Some .. vs None difference early, then we try to access .tail on a None value.

I believe JavaScript implementation does something similar to capture these case early (line 474 - 476)

export function equals<T>(x: T, y: T): boolean {
if (x === y) {
return true;
} else if (x == null) {
return y == null;
} else if (y == null) {
return false;
} else if (isEquatable(x)) {
return x.Equals(y);
} else if (isArrayLike(x)) {
return isArrayLike(y) && equalArrays(x, y);
} else if (typeof x !== "object") {
return false;
} else if (x instanceof Date) {
return (y instanceof Date) && compareDates(x, y) === 0;
} else {
return Object.getPrototypeOf(x)?.constructor === Object && equalObjects(x, y);
}
}

I am not sure what a is b does in Python, so I let it there and disabled the None, None check as it was already handled by a is b.

Also, I can't "fix" List.equal definition because this is coming from List.fs so I expect that it's implementation is correct and behaving the same as in FSharp.Core

@MangelMaxime MangelMaxime force-pushed the fix/list_option_comparaison branch from 4725aea to 51e0842 Compare November 28, 2023 13:36
Copy link
Collaborator

@dbrattli dbrattli left a comment

Choose a reason for hiding this comment

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

Very nice. I took the liberty to move all the test logic inside the match statement. Btw a is b in Python is the same as reference equals, i.e points to the same object. There's only one None instance so all Nones are the same reference.

@MangelMaxime
Copy link
Member Author

I took the liberty to move all the test logic inside the match statement.

You did good.

Thanks for explanation for a i b

@MangelMaxime MangelMaxime merged commit 34fb883 into main Nov 28, 2023
15 checks passed
@MangelMaxime MangelMaxime deleted the fix/list_option_comparaison branch March 1, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Python] Comparison with None fails
2 participants