@@ -145,8 +145,7 @@ module Exp = struct
145
145
146
146
let has_trailing_attributes {pexp_desc; pexp_attributes; _} =
147
147
match pexp_desc with
148
- | Pexp_fun _ | Pexp_function _ | Pexp_ifthenelse _ | Pexp_match _
149
- | Pexp_try _ ->
148
+ | Pexp_function _ | Pexp_ifthenelse _ | Pexp_match _ | Pexp_try _ ->
150
149
false
151
150
| _ -> List. exists pexp_attributes ~f: (Fn. non Attr. is_doc)
152
151
@@ -180,12 +179,14 @@ module Exp = struct
180
179
| ( {pexp_desc= Pexp_sequence _; _}
181
180
, (Non_apply | Sequence | Then | ThenElse ) )
182
181
| ( { pexp_desc=
183
- ( Pexp_function _ | Pexp_match _ | Pexp_try _
184
- | Pexp_fun (_, {pexp_desc= Pexp_constraint _; _}) )
182
+ ( Pexp_function (_, Some _, _)
183
+ | Pexp_function (_, _, Pfunction_cases _)
184
+ | Pexp_match _ | Pexp_try _ )
185
185
; _ }
186
186
, (Match | Let_match | Non_apply ) )
187
187
| ( { pexp_desc=
188
- ( Pexp_fun _ | Pexp_let _ | Pexp_letop _ | Pexp_letexception _
188
+ ( Pexp_function (_, _, Pfunction_body _)
189
+ | Pexp_let _ | Pexp_letop _ | Pexp_letexception _
189
190
| Pexp_letmodule _ | Pexp_open _ | Pexp_letopen _ )
190
191
; _ }
191
192
, (Let_match | Non_apply ) ) ->
@@ -1016,6 +1017,7 @@ end = struct
1016
1017
List. exists en1 ~f: (fun (_ , c , _ ) ->
1017
1018
Option. exists c ~f: check_type_constraint ) )
1018
1019
| Pexp_let (lbs , _ , _ ) -> assert (check_let_bindings lbs)
1020
+ | Pexp_function (_ , Some t1 , _ ) -> assert (check_type_constraint t1)
1019
1021
| _ -> assert false )
1020
1022
| Fpe _ | Fpc _ -> assert false
1021
1023
| Vc c -> assert (check_value_constraint c)
@@ -1206,15 +1208,16 @@ end = struct
1206
1208
let check_param_val (_ , _ , p ) = p == pat in
1207
1209
let check_expr_function_param param =
1208
1210
match param.pparam_desc with
1209
- | Param_val x -> check_param_val x
1210
- | Param_newtype _ -> false
1211
+ | Pparam_val x -> check_param_val x
1212
+ | Pparam_newtype _ -> false
1211
1213
in
1212
1214
let check_class_function_param param =
1213
1215
check_param_val param.pparam_desc
1214
1216
in
1215
1217
let check_class_function_params =
1216
1218
List. exists ~f: check_class_function_param
1217
1219
in
1220
+ let check_cases = List. exists ~f: (fun c -> c.pc_lhs == pat) in
1218
1221
match ctx with
1219
1222
| Pld (PPat (p1 , _ )) -> assert (p1 == pat)
1220
1223
| Pld _ -> assert false
@@ -1266,13 +1269,17 @@ end = struct
1266
1269
| Pexp_letop {let_; ands; _} ->
1267
1270
let f {pbop_pat; _} = check_subpat pbop_pat in
1268
1271
assert (f let_ || List. exists ~f ands)
1269
- | Pexp_function cases | Pexp_match (_ , cases ) | Pexp_try (_ , cases ) ->
1270
- assert (
1271
- List. exists cases ~f: (function
1272
- | {pc_lhs; _} when pc_lhs == pat -> true
1273
- | _ -> false ) )
1272
+ | Pexp_match (_ , cases ) | Pexp_try (_ , cases ) ->
1273
+ assert (check_cases cases)
1274
1274
| Pexp_for (p , _ , _ , _ , _ ) -> assert (p == pat)
1275
- | Pexp_fun (p , _ ) -> assert (check_expr_function_param p) )
1275
+ | Pexp_function (params , _ , body ) ->
1276
+ let check_body =
1277
+ match body with
1278
+ | Pfunction_body _ -> false
1279
+ | Pfunction_cases (cases , _ , _ ) -> check_cases cases
1280
+ in
1281
+ assert (
1282
+ List. exists ~f: check_expr_function_param params || check_body ) )
1276
1283
| Fpe ctx -> assert (check_expr_function_param ctx)
1277
1284
| Fpc ctx -> assert (check_class_function_param ctx)
1278
1285
| Vc _ -> assert false
@@ -1329,15 +1336,21 @@ end = struct
1329
1336
let check_param_val (_ , e , _ ) = Option. exists e ~f: (fun x -> x == exp) in
1330
1337
let check_expr_function_param param =
1331
1338
match param.pparam_desc with
1332
- | Param_val x -> check_param_val x
1333
- | Param_newtype _ -> false
1339
+ | Pparam_val x -> check_param_val x
1340
+ | Pparam_newtype _ -> false
1334
1341
in
1335
1342
let check_class_function_param param =
1336
1343
check_param_val param.pparam_desc
1337
1344
in
1338
1345
let check_class_function_params =
1339
1346
List. exists ~f: check_class_function_param
1340
1347
in
1348
+ let check_cases =
1349
+ List. exists ~f: (function
1350
+ | {pc_guard = Some g ; _} when g == exp -> true
1351
+ | {pc_rhs; _} when pc_rhs == exp -> true
1352
+ | _ -> false )
1353
+ in
1341
1354
match ctx with
1342
1355
| Pld (PPat (_ , Some e1 )) -> assert (e1 == exp)
1343
1356
| Pld _ -> assert false
@@ -1359,15 +1372,16 @@ end = struct
1359
1372
let f {pbop_exp; _} = pbop_exp == exp in
1360
1373
assert (f let_ || List. exists ~f ands || body == exp)
1361
1374
| (Pexp_match (e , _ ) | Pexp_try (e , _ )) when e == exp -> ()
1362
- | Pexp_function cases | Pexp_match (_, cases) | Pexp_try (_, cases)
1363
- ->
1375
+ | Pexp_match (_ , cases ) | Pexp_try (_ , cases ) ->
1376
+ assert (check_cases cases)
1377
+ | Pexp_function (params , _ , body ) ->
1378
+ let check_body =
1379
+ match body with
1380
+ | Pfunction_body body -> body == exp
1381
+ | Pfunction_cases (cases , _ , _ ) -> check_cases cases
1382
+ in
1364
1383
assert (
1365
- List. exists cases ~f: (function
1366
- | {pc_guard = Some g ; _} when g == exp -> true
1367
- | {pc_rhs; _} when pc_rhs == exp -> true
1368
- | _ -> false ) )
1369
- | Pexp_fun (param , body ) ->
1370
- assert (check_expr_function_param param || body == exp)
1384
+ List. exists ~f: check_expr_function_param params || check_body )
1371
1385
| Pexp_indexop_access {pia_lhs; pia_kind = Builtin idx ; pia_rhs; _} ->
1372
1386
assert (
1373
1387
pia_lhs == exp || idx == exp
@@ -1867,7 +1881,7 @@ end = struct
1867
1881
| Ppat_cons _ -> true
1868
1882
| Ppat_construct _ | Ppat_record _ | Ppat_variant _ -> false
1869
1883
| _ -> true )
1870
- | Fpe {pparam_desc = Param_val (_ , _ , _ ); _} , Ppat_cons _ -> true
1884
+ | Fpe {pparam_desc = Pparam_val (_ , _ , _ ); _} , Ppat_cons _ -> true
1871
1885
| Fpc {pparam_desc = _ ; _} , Ppat_cons _ -> true
1872
1886
| Pat {ppat_desc = Ppat_construct _ ; _} , Ppat_cons _ -> true
1873
1887
| _ , Ppat_constraint (_ , {ptyp_desc = Ptyp_poly _ ; _} ) -> false
@@ -1901,7 +1915,7 @@ end = struct
1901
1915
( Ppat_construct _ | Ppat_exception _ | Ppat_or _
1902
1916
| Ppat_lazy _ | Ppat_tuple _ | Ppat_variant _ | Ppat_list _ )
1903
1917
; _ }
1904
- | Exp {pexp_desc= Pexp_fun _ ; _} )
1918
+ | Exp {pexp_desc= Pexp_function (_, _, Pfunction_body _) ; _} )
1905
1919
, Ppat_alias _ )
1906
1920
| ( Pat {ppat_desc= Ppat_lazy _; _}
1907
1921
, ( Ppat_construct _ | Ppat_cons _
@@ -1917,14 +1931,14 @@ end = struct
1917
1931
| Pat {ppat_desc= Ppat_tuple _; _}, Ppat_tuple _
1918
1932
| Pat _, Ppat_lazy _
1919
1933
| Pat _, Ppat_exception _
1920
- | Exp {pexp_desc= Pexp_fun _ ; _}, Ppat_or _
1934
+ | Exp {pexp_desc= Pexp_function (_, _, Pfunction_body _) ; _}, Ppat_or _
1921
1935
| Cl {pcl_desc= Pcl_fun _; _}, Ppat_variant (_, Some _)
1922
1936
| Cl {pcl_desc= Pcl_fun _; _}, Ppat_tuple _
1923
1937
| Cl {pcl_desc= Pcl_fun _; _}, Ppat_construct _
1924
1938
| Cl {pcl_desc= Pcl_fun _; _}, Ppat_alias _
1925
1939
| Cl {pcl_desc= Pcl_fun _; _}, Ppat_lazy _
1926
1940
| (Exp {pexp_desc= Pexp_letop _; _} | Bo _), Ppat_exception _
1927
- | ( Exp {pexp_desc= Pexp_fun _ ; _}
1941
+ | ( Exp {pexp_desc= Pexp_function (_, _, Pfunction_body _) ; _}
1928
1942
, ( Ppat_construct _ | Ppat_cons _ | Ppat_lazy _ | Ppat_tuple _
1929
1943
| Ppat_variant _ ) ) ->
1930
1944
true
@@ -1976,7 +1990,7 @@ end = struct
1976
1990
match exp.pexp_desc with
1977
1991
| Pexp_assert e
1978
1992
| Pexp_construct (_, Some e)
1979
- | Pexp_fun (_, e)
1993
+ | Pexp_function (_, _, Pfunction_body e)
1980
1994
| Pexp_ifthenelse (_, Some e)
1981
1995
| Pexp_prefix (_, e)
1982
1996
| Pexp_infix (_, _, e)
@@ -2004,8 +2018,9 @@ end = struct
2004
2018
match cls with Match | Then | ThenElse -> continue e | _ -> false )
2005
2019
| Pexp_match _ when match cls with Then -> true | _ -> false ->
2006
2020
false
2007
- | Pexp_function cases | Pexp_match (_, cases) | Pexp_try (_, cases)
2008
- ->
2021
+ | Pexp_function (_, _, Pfunction_cases (cases, _, _))
2022
+ | Pexp_match (_, cases)
2023
+ | Pexp_try (_ , cases ) ->
2009
2024
continue (List. last_exn cases).pc_rhs
2010
2025
| Pexp_apply (_ , args ) -> continue (snd (List. last_exn args))
2011
2026
| Pexp_tuple es -> continue (List. last_exn es)
@@ -2057,7 +2072,7 @@ end = struct
2057
2072
| Pexp_lazy e
2058
2073
| Pexp_open (_, e)
2059
2074
| Pexp_letopen (_, e)
2060
- | Pexp_fun (_, e)
2075
+ | Pexp_function (_, _, Pfunction_body e)
2061
2076
| Pexp_sequence (_, e)
2062
2077
| Pexp_setfield (_, _, e)
2063
2078
| Pexp_setinstvar (_, e)
@@ -2073,13 +2088,16 @@ end = struct
2073
2088
| Pexp_extension (ext, PStr [{pstr_desc= Pstr_eval (e, _); _}])
2074
2089
when Source. extension_using_sugar ~name: ext ~payload: e.pexp_loc -> (
2075
2090
match e.pexp_desc with
2076
- | Pexp_function cases | Pexp_match (_, cases) | Pexp_try (_, cases)
2077
- ->
2091
+ | Pexp_function (_, _, Pfunction_cases (cases, _, _))
2092
+ | Pexp_match (_, cases)
2093
+ | Pexp_try (_ , cases ) ->
2078
2094
List. iter cases ~f: (fun case ->
2079
2095
mark_parenzed_inner_nested_match case.pc_rhs ) ;
2080
2096
true
2081
2097
| _ -> continue e )
2082
- | Pexp_function cases | Pexp_match (_ , cases ) | Pexp_try (_ , cases ) ->
2098
+ | Pexp_function (_, _, Pfunction_cases (cases, _, _))
2099
+ | Pexp_match (_, cases)
2100
+ | Pexp_try (_ , cases ) ->
2083
2101
List. iter cases ~f: (fun case ->
2084
2102
mark_parenzed_inner_nested_match case.pc_rhs ) ;
2085
2103
true
@@ -2241,6 +2259,10 @@ end = struct
2241
2259
, {pexp_desc= Pexp_construct _ | Pexp_cons _; _} )
2242
2260
when e == exp ->
2243
2261
true
2262
+ | ( Exp {pexp_desc= Pexp_function (_, _, Pfunction_body e); _}
2263
+ , {pexp_desc= Pexp_function (_, _, Pfunction_cases _); _} )
2264
+ when e == exp ->
2265
+ true
2244
2266
| Exp {pexp_desc; _} , _ -> (
2245
2267
match pexp_desc with
2246
2268
| Pexp_extension
@@ -2249,13 +2271,14 @@ end = struct
2249
2271
[ { pstr_desc=
2250
2272
Pstr_eval
2251
2273
( { pexp_desc=
2252
- ( Pexp_function cases
2274
+ ( Pexp_function
2275
+ (_, _, Pfunction_cases (cases, _, _))
2253
2276
| Pexp_match (_, cases)
2254
2277
| Pexp_try (_, cases) )
2255
2278
; _ }
2256
2279
, _ )
2257
2280
; _ } ] )
2258
- | Pexp_function cases
2281
+ | Pexp_function (_, _, Pfunction_cases ( cases, _, _))
2259
2282
| Pexp_match (_, cases)
2260
2283
| Pexp_try (_ , cases ) ->
2261
2284
if ! leading_nested_match_parens then
0 commit comments