summaryrefslogtreecommitdiff
path: root/testsuite/tests/warnings/w59.ml
blob: 9d8cd4cec8efa597271d669881773e94ed02fc71 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
(* TEST_BELOW
(* Blank lines added here to preserve locations. *)



















*)

(* Check that the warning 59 (assignment to immutable value) does not
   trigger on those examples *)
let a = Lazy.force (lazy "a")
let b = Lazy.force (lazy 1)
let c = Lazy.force (lazy 3.14)
let d = Lazy.force (lazy 'a')
let e = Lazy.force (lazy (fun x -> x+1))
let rec f (x:int) : int = g x and g x = f x
let h = Lazy.force (lazy f)
let i = Lazy.force (lazy g)
let j = Lazy.force (lazy 1L)
let k = Lazy.force (lazy (1,2))
let l = Lazy.force (lazy [|3.14|])
let m = Lazy.force (lazy (Sys.opaque_identity 3.14))
let n = Lazy.force (lazy None)

(* Check that obviously wrong code is reported *)
let o = (1,2)
let p = fun x -> x
let q = 3.14
let r = 1

let () =
  Obj.set_field (Obj.repr o) 0 (Obj.repr 3);
  Obj.set_field (Obj.repr p) 0 (Obj.repr 3);
  Obj.set_field (Obj.repr q) 0 (Obj.repr 3);
  Obj.set_field (Obj.repr r) 0 (Obj.repr 3)

let set v =
  Obj.set_field (Obj.repr v) 0 (Obj.repr 3)
  [@@inline]

let () =
  set o

(* Sys.opaque_identity hides all information and shouldn't warn *)

let opaque = Sys.opaque_identity (1,2)
let set_opaque =
  Obj.set_field
    (Obj.repr opaque)
    0
    (Obj.repr 3)

(* TEST
 flags = "-w +A-70";
 compile_only = "true";
 {
   setup-ocamlc.byte-build-env;
   ocamlc.byte;
   check-ocamlc.byte-output;
 }{
   no-flambda;
   setup-ocamlopt.byte-build-env;
   ocamlopt.byte;
   check-ocamlopt.byte-output;
 }{
   compiler_reference = "${test_source_directory}/w59.flambda.reference";
   flags = "-w +A-70 -dflambda-invariants";
   flambda;
   setup-ocamlopt.byte-build-env;
   ocamlopt.byte;
   check-ocamlopt.byte-output;
 }
*)