@@ -638,14 +638,14 @@ let compile output_prefix =
638638          Some  ((String  name, lam) :: string_table)
639639        |  _ , _  -> None )
640640      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 =  
644644    match  use_compile_literal_cases cases ~get_tag  with  
645645    |  Some  string_cases  -> 
646646      if  untagged then  
647647        compile_untagged_cases ~cxt  ~switch_exp  ~block_cases  ~default  
648-           string_cases 
648+           ~has_null_case   string_cases 
649649      else  compile_string_cases ~cxt  ~switch_exp  ~default  string_cases 
650650    |  None  -> 
651651      cases 
@@ -718,7 +718,7 @@ let compile output_prefix =
718718        else  
719719          (*  [e] will be used twice  *)  
720720          let  dispatch  e  =  
721-             let  is_a_literal_case =  
721+             let  is_a_literal_case  ()   =  
722722              if  untagged then  
723723                E. is_a_literal_case 
724724                  ~literal_cases: (get_literal_cases sw_names) 
@@ -740,13 +740,17 @@ let compile output_prefix =
740740              &&  List. length sw_consts =  0  
741741              &&  eq_default sw_num_default sw_blocks_default 
742742            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  
743747              compile_cases ~untagged  ~cxt  
744748                ~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 
747751            else  
748752              [ 
749-                 S. if_ is_a_literal_case 
753+                 S. if_ ( is_a_literal_case  () )  
750754                  (compile_cases ~cxt  ~switch_exp: e ~block_cases  
751755                     ~default: sw_num_default ~get_tag: get_const_tag sw_consts) 
752756                  ~else_:  
@@ -789,16 +793,17 @@ let compile output_prefix =
789793         ~switch: (fun  ?default   ?declaration   e  clauses  -> 
790794           S. string_switch ?default ?declaration e clauses) 
791795         ~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  =  
793798    let  mk_eq  (i  : Ast_untagged_variants.tag_type option ) x  j  y  =  
794799      let  check =  
795800        match  (i, j) with  
796801        |  Some  tag_type , _  -> 
797802          Ast_untagged_variants.DynamicChecks. add_runtime_type_check ~tag_type  
798-             ~block_cases  (Expr  x) (Expr  y) 
803+             ~has_null_case    ~ block_casesExpr  x) (Expr  y) 
799804        |  _ , Some  tag_type  -> 
800805          Ast_untagged_variants.DynamicChecks. add_runtime_type_check ~tag_type  
801-             ~block_cases  (Expr  y) (Expr  x) 
806+             ~has_null_case    ~ block_casesExpr  y) (Expr  x) 
802807        |  _  -> Ast_untagged_variants.DynamicChecks. ( ==  ) (Expr  x) (Expr  y) 
803808      in  
804809      E. emit_check check 
0 commit comments