summaryrefslogtreecommitdiff
path: root/testsuite/tests/parsetree/locations_test.ml
blob: e295d9a4caab541165b3ed57ffff46b243032608 (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
(* TEST
   flags = "-dparsetree"
   * toplevel *)

(* Using a toplevel test and not an expect test, because the locs get shifted
   by the expect blocks and the output is therefore not stable. *)

(* Attributes *)

module type S = sig end [@attr payload];;


module M = struct end [@attr payload];;

type t = int [@attr payload];;

3 [@attr payload];;

exception Exn [@@attr payload];;

(* Functors *)

module type F = functor (A : S) (B : S) -> sig end;;

module F = functor (A : S) (B : S) -> struct end;;

(* with type *)

module type S1 = sig type t end;;

module type T1 = S1 with type t = int;;

module type T1 = S1 with type t := int;;

(* Constrained bindings *)

let x : int = 3;;

let x : type a. a -> a = fun x -> x;;

let _ = object
  method x : type a. a -> a =
    fun x -> x
end;;

(* Punning. *)

let x contents = { contents };;

let x = { contents : int = 3 };;

let x contents = { contents : int };;

let x = function { contents } -> contents;;

let x = function { contents : int } -> contents;;

let x = function { contents : int = i } -> i;;

let _ =
  object val foo = 12 method x foo = {< foo >} end
;;

(* Local open *)

let x = M.{ contents = 3 };;

let x = M.[ 3; 4 ];;

let x = M.( 3; 4 );;

(* Indexing operators *)

  (* some prerequisites. *)

let ( .@() ) x y = x + y
let ( .@()<- ) x y z = x + y + z
let ( .%.{} ) x y = x + y
let ( .%.{}<- ) x y z = x + y + z
let ( .%.[] ) x y = x + y
let ( .%.[]<- ) x y z = x + y + z;;

  (* the actual issue *)

x.@(4);;
x.@(4) <- 4;;

x.%.{4};;
x.%.{4} <- 4;;

x.%.[4];;
x.%.[4] <- 4;;

(* Constrained unpacks *)

let f = function (module M : S) -> ();;

(* local opens in class and class types *)

class c =
  let open M in
  object end
;;

class type ct =
  let open M in
  object end
;;

(* Docstrings *)

(** Some docstring attached to x. *)
let x =
  42
(** Another docstring attached to x. *)
;;

(* No surrounding parentheses for immediate objects *)
let x = object method f = 1 end;;
let x = object method f = 1 end # f;;
let x = Some object method f = 1 end;;
let x = Some object method f = 1 end # f;;

let f x y z = x in
f object method f = 1 end
  object method f = 1 end # f
  object end
;;

(* Punning of labelled function argument with type constraint *)
let g y =
  let f ~y = y + 1 in
  f ~(y:int)
;;