summaryrefslogtreecommitdiff
path: root/testsuite/tests/typing-core-bugs/unit_fun_hints.ml
blob: 73b4ad22d63994aa7547a4e8129da834445b253a (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
(* TEST
   flags = "-strict-sequence"
   * expect
*)

let g f = f ()
let _ = g 3;;       (* missing `fun () ->' *)

[%%expect{|
val g : (unit -> 'a) -> 'a = <fun>
Line 2, characters 10-11:
2 | let _ = g 3;;       (* missing `fun () ->' *)
              ^
Error: This expression has type int but an expression was expected of type
         unit -> 'a
       Hint: Did you forget to wrap the expression using `fun () ->'?
|}];;


let _ =
   print_int 3;
   print_newline;    (* missing unit argument *)
   print_int 5;;

(* We use -strict-sequence for this test: otherwise only a warning is produced
   about print_newline not being of type unit *)
[%%expect{|
Line 3, characters 3-16:
3 |    print_newline;    (* missing unit argument *)
       ^^^^^^^^^^^^^
Error: This expression has type unit -> unit
       but an expression was expected of type unit
       because it is in the left-hand side of a sequence
       Hint: Did you forget to provide `()' as argument?
|}];;

let x = read_int in   (* missing unit argument *)
print_int x;;

[%%expect{|
Line 2, characters 10-11:
2 | print_int x;;
              ^
Error: This expression has type unit -> int
       but an expression was expected of type int
       Hint: Did you forget to provide `()' as argument?
|}];;

let g f =
  let _ = f () in
  f = 3;;

[%%expect{|
Line 3, characters 6-7:
3 |   f = 3;;
          ^
Error: This expression has type int but an expression was expected of type
         unit -> 'a
       Hint: Did you forget to wrap the expression using `fun () ->'?
|}];;

let g f =
  let _ = f () in
  3 = f;;

[%%expect{|
Line 3, characters 6-7:
3 |   3 = f;;
          ^
Error: This expression has type unit -> 'a
       but an expression was expected of type int
       Hint: Did you forget to provide `()' as argument?
|}]