Skip to content

Commit eaf8e7b

Browse files
committed
Fix issue with pattern matching empty list which interferes with boolean 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
1 parent a343795 commit eaf8e7b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+728
-660
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Editor: Fix issue where pipe completions would not trigger with generic type arguments. https://github.com/rescript-lang/rescript/pull/7231
1818
- Fix leftover assert false in code for `null != undefined`. https://github.com/rescript-lang/rescript/pull/7232
1919
- Editor: Fix issue where completions would not show up inside of object bodies. https://github.com/rescript-lang/rescript/pull/7230
20+
- Fix issue with pattern matching empty list which interferes with boolean optimisations. https://github.com/rescript-lang/rescript/pull/7237
2021

2122
#### :house: Internal
2223

compiler/ml/matching.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2245,7 +2245,8 @@ let combine_constructor sw_names loc arg ex_pat cstr partial ctx def
22452245
let arg =
22462246
if Datarepr.constructor_has_optional_shape cstr then
22472247
Lprim (Pis_not_none, [arg], loc)
2248-
else arg
2248+
else
2249+
Lprim (Pjscomp Cneq, [arg; Lconst (Const_base (Const_int 0))], loc)
22492250
in
22502251
Lifthenelse (arg, act2, act1)
22512252
| 2, 0, [(i1, act1); (_, act2)], []

0 commit comments

Comments
 (0)