Skip to content

Commit dffa872

Browse files
ppx: improve handling of value binding constraints
1 parent af90690 commit dffa872

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

src/ppx/ppx_lwt.ml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,32 @@ let gen_binds e_loc l e =
7575
let loc = e_loc in
7676
match binding.pvb_constraint with
7777
| None -> [%expr (fun [%p binding.pvb_pat] -> [%e aux (i+1) t])]
78-
| Some (Pvc_constraint { locally_abstract_univars = []; typ }) -> [%expr (fun ([%p binding.pvb_pat] : [%t typ]) -> [%e aux (i+1) t])]
79-
(*
80-
| Some (Pvc_constraint { locally_abstract_univars = _::_; typ= _}) -> failwith "what to do here"
81-
| Some (Pvc_coercion { ground = None; coercion }) -> [%expr (fun ([%p binding.pvb_pat] :> [%t coercion]) -> [%e aux (i+1) t])]
82-
| Some (Pvc_coercion { ground = Some ground; coercion }) -> [%expr (fun ([%p binding.pvb_pat] : [%t ground] :> [%t coercion]) -> [%e aux (i+1) t])]
78+
| Some (Pvc_constraint { locally_abstract_univars = []; typ }) ->
79+
[%expr (fun ([%p binding.pvb_pat] : [%t typ]) -> [%e aux (i+1) t])]
80+
(* TODO: I don't know how to trigger this
81+
| Some constraint_ pv ->
82+
begin match binding.pvb_pat.ppat_desc with
83+
| Ppat_var pv ->
84+
let e =
85+
let open Ast_builder.Default in
86+
pexp_let ~loc
87+
Nonrecursive
88+
[
89+
Latest.value_binding ~constraint_
90+
~loc
91+
~pat:binding.pvb_pat
92+
~expr:(pexp_ident ~loc {loc=pv.loc; txt=Lident pv.txt})
93+
()
94+
]
95+
(aux (i+1) t)
96+
in
97+
[%expr (fun [%p binding.pvb_pat] -> [%e e])]
98+
| _ ->
99+
Location.Error.(raise (make ~loc "unsupported value binding constraint" ~sub:[]))
100+
end
83101
*)
84-
| _ -> failwith "WIP: what to do here"
102+
| _ ->
103+
Location.Error.(raise (make ~loc "unsupported value binding constraint" ~sub:[]))
85104
in
86105
let new_exp =
87106
let loc = e_loc in

test/ppx/main.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ let suite = suite "ppx" [
171171
let%lwt (_ : int) = Lwt.return 0 in
172172
Lwt.return_true
173173
) ;
174+
test "1085-int-again"
175+
(fun () ->
176+
let%lwt _ : int = Lwt.return 0 in
177+
Lwt.return_true
178+
) ;
179+
test "1085-any"
180+
(fun () ->
181+
let%lwt _ : _ = Lwt.return 0 in
182+
Lwt.return_true
183+
) ;
174184
]
175185

176186
let _ = Test.run "ppx" [ suite ]

0 commit comments

Comments
 (0)