@@ -638,14 +638,14 @@ let compile output_prefix =
638
638
Some ((String name, lam) :: string_table)
639
639
| _ , _ -> None )
640
640
table (Some [] )
641
- and compile_cases ?(untagged = false ) ~ cxt ~( switch_exp : E.t )
642
- ?(default = NonComplete ) ?(get_tag = fun _ -> None ) ?(block_cases = [] )
643
- cases : initialization =
641
+ and compile_cases ?(untagged = false ) ?( has_null_case = false ) ~ cxt
642
+ ~( switch_exp : E.t ) ?(default = NonComplete ) ?(get_tag = fun _ -> None )
643
+ ?(block_cases = [] ) cases : initialization =
644
644
match use_compile_literal_cases cases ~get_tag with
645
645
| Some string_cases ->
646
646
if untagged then
647
647
compile_untagged_cases ~cxt ~switch_exp ~block_cases ~default
648
- string_cases
648
+ ~has_null_case string_cases
649
649
else compile_string_cases ~cxt ~switch_exp ~default string_cases
650
650
| None ->
651
651
cases
@@ -718,7 +718,7 @@ let compile output_prefix =
718
718
else
719
719
(* [e] will be used twice *)
720
720
let dispatch e =
721
- let is_a_literal_case =
721
+ let is_a_literal_case () =
722
722
if untagged then
723
723
E. is_a_literal_case
724
724
~literal_cases: (get_literal_cases sw_names)
@@ -740,13 +740,17 @@ let compile output_prefix =
740
740
&& List. length sw_consts = 0
741
741
&& eq_default sw_num_default sw_blocks_default
742
742
then
743
+ let literal_cases = get_literal_cases sw_names in
744
+ let has_null_case =
745
+ List. mem Ast_untagged_variants. Null literal_cases
746
+ in
743
747
compile_cases ~untagged ~cxt
744
748
~switch_exp: (if untagged then e else E. tag ~name: tag_name e)
745
- ~block_cases ~default: sw_blocks_default ~get_tag: get_block_tag
746
- sw_blocks
749
+ ~block_cases ~has_null_case ~default: sw_blocks_default
750
+ ~get_tag: get_block_tag sw_blocks
747
751
else
748
752
[
749
- S. if_ is_a_literal_case
753
+ S. if_ ( is_a_literal_case () )
750
754
(compile_cases ~cxt ~switch_exp: e ~block_cases
751
755
~default: sw_num_default ~get_tag: get_const_tag sw_consts)
752
756
~else_:
@@ -789,16 +793,17 @@ let compile output_prefix =
789
793
~switch: (fun ?default ?declaration e clauses ->
790
794
S. string_switch ?default ?declaration e clauses)
791
795
~switch_exp ~default
792
- and compile_untagged_cases ~cxt ~switch_exp ~default ~block_cases cases =
796
+ and compile_untagged_cases ~cxt ~switch_exp ~default ~block_cases
797
+ ~has_null_case cases =
793
798
let mk_eq (i : Ast_untagged_variants.tag_type option ) x j y =
794
799
let check =
795
800
match (i, j) with
796
801
| Some tag_type , _ ->
797
802
Ast_untagged_variants.DynamicChecks. add_runtime_type_check ~tag_type
798
- ~block_cases (Expr x) (Expr y)
803
+ ~has_null_case ~ block_cases (Expr x) (Expr y)
799
804
| _ , Some tag_type ->
800
805
Ast_untagged_variants.DynamicChecks. add_runtime_type_check ~tag_type
801
- ~block_cases (Expr y) (Expr x)
806
+ ~has_null_case ~ block_cases (Expr y) (Expr x)
802
807
| _ -> Ast_untagged_variants.DynamicChecks. ( == ) (Expr x) (Expr y)
803
808
in
804
809
E. emit_check check
0 commit comments