@@ -61,8 +61,8 @@ let longident_is_simple c x =
61
61
let rec length x =
62
62
match x with
63
63
| Longident. Lident x -> String. length x
64
- | Ldot (x , y ) -> length x + 1 + String. length y
65
- | Lapply (x , y ) -> length x + length y + 3
64
+ | Ldot (x , y ) -> length x.txt + 1 + String. length y.txt
65
+ | Lapply (x , y ) -> length x.txt + length y.txt + 3
66
66
in
67
67
longident_fit_margin c (length x)
68
68
@@ -977,14 +977,15 @@ end = struct
977
977
| Ptyp_alias (t1 , _ ) | Ptyp_poly (_ , t1 ) -> assert (typ == t1)
978
978
| Ptyp_arrow (t , t2 ) ->
979
979
assert (List. exists t ~f: (fun x -> typ == x.pap_type) || typ == t2)
980
- | Ptyp_tuple t1N | Ptyp_constr (_ , t1N ) -> assert (List. exists t1N ~f )
980
+ | Ptyp_tuple t1N -> assert (List. exists t1N ~f: snd_f)
981
+ | Ptyp_constr (_ , t1N ) -> assert (List. exists t1N ~f )
981
982
| Ptyp_variant (r1N , _ , _ ) ->
982
983
assert (
983
984
List. exists r1N ~f: (function
984
985
| {prf_desc = Rtag (_ , _ , t1N ); _} -> List. exists t1N ~f
985
986
| {prf_desc = Rinherit t1 ; _} -> typ == t1 ) )
986
987
| Ptyp_open (_ , t1 ) -> assert (t1 == typ)
987
- | Ptyp_package ( _ , it1N , _ ) -> assert (List. exists it1N ~f: snd_f)
988
+ | Ptyp_package ptyp -> assert (List. exists ptyp.ppt_cstrs ~f: snd_f)
988
989
| Ptyp_object (fields , _ ) ->
989
990
assert (
990
991
List. exists fields ~f: (function
@@ -1017,15 +1018,15 @@ end = struct
1017
1018
match ctx.ppat_desc with
1018
1019
| Ppat_constraint (_ , t1 ) -> assert (typ == t1)
1019
1020
| Ppat_extension (_ , PTyp t ) -> assert (typ == t)
1020
- | Ppat_unpack (_ , Some ( _ , l , _ ) ) ->
1021
- assert (List. exists l ~f: (fun (_ , t ) -> typ == t))
1021
+ | Ppat_unpack (_ , Some ptyp ) ->
1022
+ assert (List. exists ptyp.ppt_cstrs ~f: (fun (_ , t ) -> typ == t))
1022
1023
| Ppat_record (l , _ ) ->
1023
1024
assert (List. exists l ~f: (fun (_ , t , _ ) -> Option. exists t ~f ))
1024
1025
| _ -> assert false )
1025
1026
| Exp ctx -> (
1026
1027
match ctx.pexp_desc with
1027
- | Pexp_pack (_ , Some ( _ , it1N , _ ) , _ ) ->
1028
- assert (List. exists it1N ~f: snd_f)
1028
+ | Pexp_pack (_ , Some ptyp , _ ) ->
1029
+ assert (List. exists ptyp.ppt_cstrs ~f: snd_f)
1029
1030
| Pexp_constraint (_, t1)
1030
1031
| Pexp_coerce (_, None , t1)
1031
1032
| Pexp_extension (_ , PTyp t1 ) ->
@@ -1063,7 +1064,7 @@ end = struct
1063
1064
| Mod ctx -> (
1064
1065
match ctx.pmod_desc with
1065
1066
| Pmod_unpack (_ , ty1 , ty2 ) ->
1066
- let f ( _ , cstrs , _ ) = List. exists cstrs ~f: ( fun ( _ , x ) -> f x) in
1067
+ let f ptyp = List. exists ptyp.ppt_cstrs ~f: snd_f in
1067
1068
assert (Option. exists ty1 ~f || Option. exists ty2 ~f )
1068
1069
| _ -> assert false )
1069
1070
| Sig ctx -> (
@@ -1255,7 +1256,9 @@ end = struct
1255
1256
| Pat ctx -> (
1256
1257
let f pI = pI == pat in
1257
1258
match ctx.ppat_desc with
1258
- | Ppat_array p1N | Ppat_list p1N | Ppat_tuple p1N | Ppat_cons p1N ->
1259
+ | Ppat_tuple (p1N , _ ) ->
1260
+ assert (List. exists p1N ~f: (fun (_ , x ) -> f x))
1261
+ | Ppat_array p1N | Ppat_list p1N | Ppat_cons p1N ->
1259
1262
assert (List. exists p1N ~f )
1260
1263
| Ppat_record (p1N , _ ) ->
1261
1264
assert (List. exists p1N ~f: (fun (_ , _ , x ) -> Option. exists x ~f ))
@@ -1423,7 +1426,8 @@ end = struct
1423
1426
| Pexp_apply (e0 , e1N ) ->
1424
1427
(* FAIL *)
1425
1428
assert (e0 == exp || List. exists e1N ~f: snd_f)
1426
- | Pexp_tuple e1N | Pexp_array e1N | Pexp_list e1N | Pexp_cons e1N ->
1429
+ | Pexp_tuple e1N -> assert (List. exists e1N ~f: snd_f)
1430
+ | Pexp_array e1N | Pexp_list e1N | Pexp_cons e1N ->
1427
1431
assert (List. exists e1N ~f )
1428
1432
| Pexp_construct (_ , e ) | Pexp_variant (_ , e ) ->
1429
1433
assert (Option. exists e ~f )
@@ -1529,7 +1533,10 @@ end = struct
1529
1533
&& fit_margin c (width xexp)
1530
1534
| Pexp_construct (_ , Some e0 ) | Pexp_variant (_ , Some e0 ) ->
1531
1535
Exp. is_trivial e0
1532
- | Pexp_array e1N | Pexp_list e1N | Pexp_tuple e1N ->
1536
+ | Pexp_tuple e1N ->
1537
+ List. for_all e1N ~f: (snd >> Exp. is_trivial)
1538
+ && fit_margin c (width xexp)
1539
+ | Pexp_array e1N | Pexp_list e1N ->
1533
1540
List. for_all e1N ~f: Exp. is_trivial && fit_margin c (width xexp)
1534
1541
| Pexp_record (e1N , e0 ) ->
1535
1542
Option. for_all e0 ~f: Exp. is_trivial
@@ -1631,7 +1638,7 @@ end = struct
1631
1638
| {ast = Typ _ ; _} -> None
1632
1639
| {ctx = Exp {pexp_desc; _} ; ast = Exp exp } -> (
1633
1640
match pexp_desc with
1634
- | Pexp_tuple (e0 :: _ ) ->
1641
+ | Pexp_tuple (( _ , e0 ) :: _ ) ->
1635
1642
Some (Comma , if exp == e0 then Left else Right )
1636
1643
| Pexp_cons l ->
1637
1644
Some (ColonColon , if exp == List. last_exn l then Right else Left )
@@ -1848,6 +1855,9 @@ end = struct
1848
1855
( Str {pstr_desc= Pstr_exception _; _}
1849
1856
| Sig {psig_desc = Psig_exception _ ; _} ) } ->
1850
1857
true
1858
+ | { ast= {ptyp_desc= Ptyp_tuple ((Some _, _) :: _); _}
1859
+ ; ctx= Typ {ptyp_desc= Ptyp_arrow _; _} } ->
1860
+ true
1851
1861
| _ -> (
1852
1862
match ambig_prec (sub_ast ~ctx (Typ typ)) with
1853
1863
| `Ambiguous -> true
@@ -2087,7 +2097,7 @@ end = struct
2087
2097
| Pexp_try (_ , cases , _ ) ->
2088
2098
continue (List. last_exn cases).pc_rhs
2089
2099
| Pexp_apply (_ , args ) -> continue (snd (List. last_exn args))
2090
- | Pexp_tuple es -> continue (List. last_exn es)
2100
+ | Pexp_tuple es -> continue (snd @@ List. last_exn es)
2091
2101
| Pexp_array _ | Pexp_list _ | Pexp_coerce _ | Pexp_constant _
2092
2102
| Pexp_constraint _
2093
2103
| Pexp_construct (_, None )
@@ -2168,7 +2178,7 @@ end = struct
2168
2178
| Pexp_indexop_access {pia_rhs = rhs ; _} -> (
2169
2179
match rhs with Some e -> continue e | None -> false )
2170
2180
| Pexp_apply (_ , args ) -> continue (snd (List. last_exn args))
2171
- | Pexp_tuple es -> continue (List. last_exn es)
2181
+ | Pexp_tuple es -> continue (snd @@ List. last_exn es)
2172
2182
| Pexp_array _ | Pexp_list _ | Pexp_coerce _ | Pexp_constant _
2173
2183
| Pexp_constraint _
2174
2184
| Pexp_construct (_, None )
@@ -2220,7 +2230,7 @@ end = struct
2220
2230
&& Option. value_map ~default: false (prec_ast ctx) ~f: (fun p ->
2221
2231
Prec. compare p Apply < 0 ) ->
2222
2232
true
2223
- | Pexp_tuple e1N -> List. last_exn e1N == xexp.ast
2233
+ | Pexp_tuple e1N -> snd ( List. last_exn e1N) == xexp.ast
2224
2234
| _ -> false
2225
2235
in
2226
2236
match ambig_prec (sub_ast ~ctx (Exp exp)) with
0 commit comments