summaryrefslogtreecommitdiff
path: root/testsuite/tests/typing-warnings/application.ml
blob: 8da9782112059e7bf22b6907720ae4df1c7f7d1e (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
(* TEST
   flags = " -w +A -strict-sequence "
   * expect
*)

(* Ignore OCAMLRUNPARAM=b to be reproducible *)
Printexc.record_backtrace false;;
[%%expect {|
- : unit = ()
|}]

let _ = Array.get;;
[%%expect {|
- : 'a array -> int -> 'a = <fun>
|}]

let _ = Array.get [||];;
[%%expect {|
Line 1, characters 8-22:
1 | let _ = Array.get [||];;
            ^^^^^^^^^^^^^^
Warning 5 [ignored-partial-application]: this function application is partial,
maybe some arguments are missing.

- : int -> 'a = <fun>
|}]

let () = ignore Array.get;;
[%%expect {|
|}]

let () = ignore (Array.get [||]);;
[%%expect {|
Line 1, characters 16-32:
1 | let () = ignore (Array.get [||]);;
                    ^^^^^^^^^^^^^^^^
Warning 5 [ignored-partial-application]: this function application is partial,
maybe some arguments are missing.
|}]


let _ = if true then Array.get else (fun _ _ -> 12);;
[%%expect {|
- : int array -> int -> int = <fun>
|}]

let _ = if true then Array.get [||] else (fun _ -> 12);;
[%%expect {|
Line 1, characters 21-35:
1 | let _ = if true then Array.get [||] else (fun _ -> 12);;
                         ^^^^^^^^^^^^^^
Warning 5 [ignored-partial-application]: this function application is partial,
maybe some arguments are missing.

- : int -> int = <fun>
|}]

let _ = (if true then Array.get [||] else (fun _ -> 12) : _ -> _);;
[%%expect {|
- : int -> int = <fun>
|}]

type t = {r: int -> int -> int}

let f x = let _ = x.r in ();;
[%%expect {|
type t = { r : int -> int -> int; }
val f : t -> unit = <fun>
|}]

let f x = let _ = x.r 1 in ();;
[%%expect {|
Line 1, characters 18-23:
1 | let f x = let _ = x.r 1 in ();;
                      ^^^^^
Warning 5 [ignored-partial-application]: this function application is partial,
maybe some arguments are missing.

val f : t -> unit = <fun>
|}]

let f a b = a + b;;
match f 42 with
| _ -> ();;
[%%expect {|
val f : int -> int -> int = <fun>
Line 2, characters 6-10:
2 | match f 42 with
          ^^^^
Warning 5 [ignored-partial-application]: this function application is partial,
maybe some arguments are missing.

- : unit = ()
|}]

let f a b = a + b;;
match f 42 with
| _ -> ()
| exception _ -> ();;
[%%expect {|
val f : int -> int -> int = <fun>
Line 2, characters 6-10:
2 | match f 42 with
          ^^^^
Warning 5 [ignored-partial-application]: this function application is partial,
maybe some arguments are missing.

- : unit = ()
|}]

let f a b = a + b;;
match f 42 with
| x -> ignore (x 34);;
[%%expect {|
val f : int -> int -> int = <fun>
- : unit = ()
|}]


let f a b = a + b;;
match (f 42 : _) with
| _ -> ();;
[%%expect {|
val f : int -> int -> int = <fun>
- : unit = ()
|}]

let _ = raise Exit 3;;
[%%expect {|
Line 1, characters 19-20:
1 | let _ = raise Exit 3;;
                       ^
Warning 20 [ignored-extra-argument]: this argument will not be used by the function.

Exception: Stdlib.Exit.
|}]

let f a b = a + b;;
[%%expect {|
val f : int -> int -> int = <fun>
|}]
let g x = x + 1
let _ = g (f 1);;
[%%expect {|
val g : int -> int = <fun>
Line 2, characters 10-15:
2 | let _ = g (f 1);;
              ^^^^^
Error: This expression has type int -> int
       but an expression was expected of type int
  Hint: This function application is partial,
  maybe some arguments are missing.
|}]