summaryrefslogtreecommitdiff
path: root/testsuite/tests/misc/exotic.ml
blob: dae81075f756536e6cd67678862ac204f6691eab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(* TEST
 flags = "-I ${ocamlsrcdir}/utils";
 expect;
*)

(* Strict-sequence can change the behavior of programs *)

(* The two examples below were proposed by Jeremy Yallop in
   https://github.com/ocaml/ocaml/pull/1971 .
   Note that those tests are here to record this behavior and not to enshrine it.
*)

[@@@warning "-non-unit-statement"];;
[@@@warning "-not-principal"];;
[@@@warning "-partial-match"];;
[@@@warning "-ignored-partial-application"];;

type t = A | () and b = B : _ -> b;;
[%%expect{|
type t = A | ()
and b = B : 'a -> b
|}];;

Clflags.strict_sequence := false ;;
let f (g : 'a) = g; Format.printf "%b@." (B (() : 'a) = B A) in f ();;
[%%expect {|
- : unit = ()
false
- : unit = ()
|}]
;;

Clflags.strict_sequence := true ;;
let f (g : 'a) = g; Format.printf "%b@." (B (() : 'a) = B A) in f ();;
[%%expect {|
- : unit = ()
true
- : unit = ()
|}]
;;

[@@@warning "-labels-omitted"];;
Clflags.strict_sequence := false;;
let f () = let g ~y = (raise Not_found : 'a) in
           if false then ((assert false : 'a); g ()) else g ()
let _ = Format.printf "%b@." (try f (); false with Not_found -> true)
[%%expect {|
- : unit = ()
val f : t -> y:'a -> 'b = <fun>
false
- : unit = ()
|}]
;;

Clflags.strict_sequence := true ;;
let f () = let g ~y = (raise Not_found : 'a) in
           if false then ((assert false : 'a); g ()) else g ()
let _ = Format.printf "%b@." (try f (); false with Not_found -> true)
[%%expect {|
- : unit = ()
val f : t -> unit = <fun>
true
- : unit = ()
|}]