@@ -298,6 +298,19 @@ Line 3, characters 4-32:
298
298
Error : Mixing value and exception patterns under when -guards is not supported .
299
299
|}];;
300
300
301
+ (* Test rejection of pattern guards on mixed exception/value or-patterns *)
302
+ let reject_guarded_val_exn_orp k =
303
+ match k () with
304
+ | Some s | exception Failure s when s match " foo" -> s
305
+ | _ -> " Not foo"
306
+ ;;
307
+ [%% expect{|
308
+ Line 3 , characters 4-32 :
309
+ 3 | | Some s | exception Failure s when s match " foo" -> s
310
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
311
+ Error : Mixing value and exception patterns under when -guards is not supported .
312
+ |}];;
313
+
301
314
module M : sig
302
315
type 'a t
303
316
@@ -509,52 +522,36 @@ let collatz = function
509
522
;;
510
523
511
524
[%% expect{|
512
- >> Fatal error : typechecking for multicase pattern guards unimplemented
513
- Uncaught exception : Misc .Fatal_error
514
-
525
+ val nested_singleway :
526
+ ('a -> 'b option ) ->
527
+ ('b -> 'c option ) -> ('c -> 'd option ) -> default :'d -> 'a option -> 'd =
528
+ < fun>
529
+ val collatz : int -> int option = < fun>
515
530
|}];;
516
531
517
532
nested_singleway collatz collatz collatz ~default: ~- 1 None ;;
518
533
[%% expect{|
519
- Line 1 , characters 0-16 :
520
- 1 | nested_singleway collatz collatz collatz ~default: ~- 1 None ;;
521
- ^^^^^^^^^^^^^^^^
522
- Error : Unbound value nested_singleway
534
+ - : int = - 1
523
535
| }];;
524
536
nested_singleway collatz collatz collatz ~default: ~- 1 (Some 1 );;
525
537
[%% expect{|
526
- Line 1 , characters 0-16 :
527
- 1 | nested_singleway collatz collatz collatz ~default: ~- 1 (Some 1 );;
528
- ^^^^^^^^^^^^^^^^
529
- Error : Unbound value nested_singleway
538
+ - : int = - 1
530
539
| }];;
531
540
nested_singleway collatz collatz collatz ~default: ~- 1 (Some 2 );;
532
541
[%% expect{|
533
- Line 1 , characters 0-16 :
534
- 1 | nested_singleway collatz collatz collatz ~default: ~- 1 (Some 2 );;
535
- ^^^^^^^^^^^^^^^^
536
- Error : Unbound value nested_singleway
542
+ - : int = - 1
537
543
| }];;
538
544
nested_singleway collatz collatz collatz ~default: ~- 1 (Some 3 );;
539
545
[%% expect{|
540
- Line 1 , characters 0-16 :
541
- 1 | nested_singleway collatz collatz collatz ~default: ~- 1 (Some 3 );;
542
- ^^^^^^^^^^^^^^^^
543
- Error : Unbound value nested_singleway
546
+ - : int = 16
544
547
| }];;
545
548
nested_singleway collatz collatz collatz ~default: ~- 1 (Some 4 );;
546
549
[%% expect{|
547
- Line 1 , characters 0-16 :
548
- 1 | nested_singleway collatz collatz collatz ~default: ~- 1 (Some 4 );;
549
- ^^^^^^^^^^^^^^^^
550
- Error : Unbound value nested_singleway
550
+ - : int = - 1
551
551
| }];;
552
552
nested_singleway collatz collatz collatz ~default: ~- 1 (Some 8 );;
553
553
[%% expect{|
554
- Line 1 , characters 0-16 :
555
- 1 | nested_singleway collatz collatz collatz ~default: ~- 1 (Some 8 );;
556
- ^^^^^^^^^^^^^^^^
557
- Error : Unbound value nested_singleway
554
+ - : int = 1
558
555
| }];;
559
556
560
557
let find_multiway ~eq ~flag ~finish ~default = function
@@ -565,9 +562,9 @@ let find_multiway ~eq ~flag ~finish ~default = function
565
562
| _ -> default
566
563
;;
567
564
[%% expect{|
568
- >> Fatal error : typechecking for multicase pattern guards unimplemented
569
- Uncaught exception : Misc .Fatal_error
570
-
565
+ val find_multiway :
566
+ eq :(' a -> 'a -> bool ) ->
567
+ flag :' a -> finish :(' a -> 'b ) -> default :' b -> 'a list -> 'b = < fun >
571
568
|}];;
572
569
573
570
let eq n m = (n - m) mod 100 = 0 ;;
@@ -583,31 +580,19 @@ val default : string = "No match found"
583
580
584
581
find_multiway ~eq ~flag ~finish ~default [ 10 ; 20 ; 110 ; 100 ];;
585
582
[%% expect{|
586
- Line 1 , characters 0-13 :
587
- 1 | find_multiway ~eq ~flag ~finish ~default [ 10 ; 20 ; 110 ; 100 ];;
588
- ^^^^^^^^^^^^^
589
- Error : Unbound value find_multiway
583
+ - : string = " 110"
590
584
| }];;
591
585
find_multiway ~eq ~flag ~finish ~default [ 10 ; 20 ; 100 ; 110 ];;
592
586
[%% expect{|
593
- Line 1 , characters 0-13 :
594
- 1 | find_multiway ~eq ~flag ~finish ~default [ 10 ; 20 ; 100 ; 110 ];;
595
- ^^^^^^^^^^^^^
596
- Error : Unbound value find_multiway
587
+ - : string = " 0"
597
588
| }];;
598
589
find_multiway ~eq ~flag ~finish ~default [ 10 ; 20 ; 30 ; 40 ];;
599
590
[%% expect{|
600
- Line 1 , characters 0-13 :
601
- 1 | find_multiway ~eq ~flag ~finish ~default [ 10 ; 20 ; 30 ; 40 ];;
602
- ^^^^^^^^^^^^^
603
- Error : Unbound value find_multiway
591
+ - : string = " No match found"
604
592
| }];;
605
593
find_multiway ~eq ~flag ~finish ~default [ 0 ; 100 ];;
606
594
[%% expect{|
607
- Line 1 , characters 0-13 :
608
- 1 | find_multiway ~eq ~flag ~finish ~default [ 0 ; 100 ];;
609
- ^^^^^^^^^^^^^
610
- Error : Unbound value find_multiway
595
+ - : string = " 0"
611
596
| }];;
612
597
613
598
let nested_multiway f g h = function
@@ -621,9 +606,9 @@ let nested_multiway f g h = function
621
606
| _ -> " not found"
622
607
;;
623
608
[%% expect{|
624
- >> Fatal error : typechecking for multicase pattern guards unimplemented
625
- Uncaught exception : Misc .Fatal_error
626
-
609
+ val nested_multiway :
610
+ ( 'a -> string ) ->
611
+ ( 'a -> string list ) -> ( 'a -> bool ) -> 'a option -> string = < fun >
627
612
|}];;
628
613
629
614
let f = function
@@ -647,45 +632,27 @@ val h : int -> bool = <fun>
647
632
648
633
nested_multiway f g h None ;;
649
634
[%% expect{|
650
- Line 1 , characters 0-15 :
651
- 1 | nested_multiway f g h None ;;
652
- ^^^^^^^^^^^^^^^
653
- Error : Unbound value nested_multiway
635
+ - : string = " not found"
654
636
| }];;
655
637
nested_multiway f g h (Some 0 );;
656
638
[%% expect{|
657
- Line 1 , characters 0-15 :
658
- 1 | nested_multiway f g h (Some 0 );;
659
- ^^^^^^^^^^^^^^^
660
- Error : Unbound value nested_multiway
639
+ - : string = " not found"
661
640
| }];;
662
641
nested_multiway f g h (Some 1 );;
663
642
[%% expect{|
664
- Line 1 , characters 0-15 :
665
- 1 | nested_multiway f g h (Some 1 );;
666
- ^^^^^^^^^^^^^^^
667
- Error : Unbound value nested_multiway
643
+ - : string = " foo1"
668
644
| }];;
669
645
nested_multiway f g h (Some 10 );;
670
646
[%% expect{|
671
- Line 1 , characters 0-15 :
672
- 1 | nested_multiway f g h (Some 10 );;
673
- ^^^^^^^^^^^^^^^
674
- Error : Unbound value nested_multiway
647
+ - : string = " bar empty"
675
648
| }];;
676
649
nested_multiway f g h (Some 100 );;
677
650
[%% expect{|
678
- Line 1 , characters 0-15 :
679
- 1 | nested_multiway f g h (Some 100 );;
680
- ^^^^^^^^^^^^^^^
681
- Error : Unbound value nested_multiway
651
+ - : string = " bar singleton one"
682
652
| }];;
683
653
nested_multiway f g h (Some 1000 );;
684
654
[%% expect{|
685
- Line 1 , characters 0-15 :
686
- 1 | nested_multiway f g h (Some 1000 );;
687
- ^^^^^^^^^^^^^^^
688
- Error : Unbound value nested_multiway
655
+ - : string = " not found"
689
656
| }];;
690
657
691
658
(* Checks that optional arguments with defaults are correclty bound in the
0 commit comments