summaryrefslogtreecommitdiff
path: root/testsuite/tests/typing-misc/apply_non_function.ml
blob: 7e768c6473c80cab384aee0c40e0562952b2ee0e (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
(* TEST
 expect;
*)

let print_lines = List.iter print_endline

let () =
  print_lines (List.map string_of_int [ 1; 2; 3; 4; 5 ])
  print_endline "foo"
[%%expect{|
val print_lines : string list -> unit = <fun>
Lines 4-5, characters 2-15:
4 | ..print_lines (List.map string_of_int [ 1; 2; 3; 4; 5 ])
5 |   print_endline......
Error: The function 'print_lines' has type string list -> unit
       It is applied to too many arguments
Line 4, characters 55-57:
4 |   print_lines (List.map string_of_int [ 1; 2; 3; 4; 5 ])
                                                           ^^
  Hint: Did you forget a ';'?
Line 5, characters 2-15:
5 |   print_endline "foo"
      ^^^^^^^^^^^^^
  This extra argument is not expected.
|}]

type t = { f : int -> unit }

let f (t : t) =
  t.f 1 2
[%%expect{|
type t = { f : int -> unit; }
Line 4, characters 2-9:
4 |   t.f 1 2
      ^^^^^^^
Error: The function 't.f' has type int -> unit
       It is applied to too many arguments
Line 4, characters 6-8:
4 |   t.f 1 2
          ^^
  Hint: Did you forget a ';'?
Line 4, characters 8-9:
4 |   t.f 1 2
            ^
  This extra argument is not expected.
|}]

let f (t : < f : int -> unit >) =
  t#f 1 2
[%%expect{|
Line 2, characters 2-9:
2 |   t#f 1 2
      ^^^^^^^
Error: The function 't#f' has type int -> unit
       It is applied to too many arguments
Line 2, characters 6-8:
2 |   t#f 1 2
          ^^
  Hint: Did you forget a ';'?
Line 2, characters 8-9:
2 |   t#f 1 2
            ^
  This extra argument is not expected.
|}]

let () =
  object
    val a = fun _ -> ()
    method b = a 1 2
  end
[%%expect{|
Line 4, characters 15-20:
4 |     method b = a 1 2
                   ^^^^^
Error: The function 'a' has type 'a -> unit
       It is applied to too many arguments
Line 4, characters 17-19:
4 |     method b = a 1 2
                     ^^
  Hint: Did you forget a ';'?
Line 4, characters 19-20:
4 |     method b = a 1 2
                       ^
  This extra argument is not expected.
|}]

(* The result of [(+) 1 2] is not [unit], we don't expect the hint to insert a
   ';'. *)

let () =
  (+) 1 2 3
[%%expect{|
Line 2, characters 2-11:
2 |   (+) 1 2 3
      ^^^^^^^^^
Error: The function '(+)' has type int -> int -> int
       It is applied to too many arguments
Line 2, characters 10-11:
2 |   (+) 1 2 3
              ^
  This extra argument is not expected.
|}]

(* The arrow type might be hidden behind a constructor. *)

type t = int -> int -> unit
let f (x:t) = x 0 1 2
[%%expect{|
type t = int -> int -> unit
Line 2, characters 14-21:
2 | let f (x:t) = x 0 1 2
                  ^^^^^^^
Error: The function 'x' has type int -> int -> unit
       It is applied to too many arguments
Line 2, characters 18-20:
2 | let f (x:t) = x 0 1 2
                      ^^
  Hint: Did you forget a ';'?
Line 2, characters 20-21:
2 | let f (x:t) = x 0 1 2
                        ^
  This extra argument is not expected.
|}]

type t = int -> unit
let f (x:int -> t) = x 0 1 2
[%%expect{|
type t = int -> unit
Line 2, characters 21-28:
2 | let f (x:int -> t) = x 0 1 2
                         ^^^^^^^
Error: The function 'x' has type int -> t
       It is applied to too many arguments
Line 2, characters 25-27:
2 | let f (x:int -> t) = x 0 1 2
                             ^^
  Hint: Did you forget a ';'?
Line 2, characters 27-28:
2 | let f (x:int -> t) = x 0 1 2
                               ^
  This extra argument is not expected.
|}]