Skip to content

Fix issue with pattern matching empty list which interferes with bool… #7237

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

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

cristianoc
Copy link
Collaborator

…ean optimisations.

The pattern matching case for empty list switch x { | list{} => used to compile to if(x), which interferes with boolean optimisation. Now it compiles to if(x ==0) which is the same output as for if(x == list{}).

Fixes #7235

…ean optimisations.

The pattern matching case  for empty list `switch x { | list{} =>` used to compile to `if(x)`, which interferes with boolean optimisation.
Now it compiles to `if(x ==0)` which is the same output as for `if(x == list{})`.

Fixes #7235
@@ -612,3 +612,11 @@ let sort_uniq = (cmp, l) => {
sort(len, l)
}
}

let isEmpty = x =>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This function now compiles to the same code as isEmpty2 below.

@cristianoc cristianoc merged commit eaf8e7b into master Jan 10, 2025
20 checks passed
@cristianoc cristianoc deleted the pattern-match-empty-list branch January 10, 2025 11:37
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.

Incorrect JS outputs when pattern matching with empty list
2 participants