Skip to content

Commit

Permalink
fix null/non-null equality, bad bug
Browse files Browse the repository at this point in the history
fixes #74
  • Loading branch information
emmanueltouzery committed Jan 10, 2023
1 parent 7d1f788 commit 5fb124e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Comparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function stringHashCode(str: string): number {
* if possible, degrades to === if not available, and is also null-safe.
*/
export function areEqual(obj: any|null, obj2: any|null): boolean {
if (obj === null != obj2 === null) {
if ((obj === null) != (obj2 === null)) {
return false;
}
if (obj === null || obj2 === null) {
Expand Down
2 changes: 2 additions & 0 deletions tests/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ describe("option comparison", () => {
assert.ok(Option.of(5).equals(Option.of(5))))
it("should mark different options as not equal", () =>
assert.ok(!Option.of(5).equals(Option.of(6))))
it("should mark different options as not equal", () =>
assert.ok(!Option.of<any>(Vector.of(12, 2674)).equals(Option.of<any>(null))))
it("should mark none as equals to none", () =>
assert.ok(Option.none<string>().equals(Option.none<string>())));
it("should mark none and some as not equal", () =>
Expand Down

0 comments on commit 5fb124e

Please sign in to comment.