Skip to content

Commit 93c95d1

Browse files
committed
Translate 'Lwt.wrap'
1 parent 052436a commit 93c95d1

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

bin/lwt_to_direct_style/ast_rewrite.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ let rewrite_apply_lwt ~backend ~state ident args =
280280
("[<?>] can't be automatically translated."
281281
^ backend#choose_comment_hint);
282282
return None
283+
| "wrap" ->
284+
take @@ fun f -> return (Some (Exp.apply f [ (Nolabel, mk_unit_val) ]))
283285
| _ -> return None
284286

285287
let string_drop_suffix ~suffix s =

test/lwt_to_direct_style/to_direct_style.t/run.t

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Make a writable directory tree:
5050
Lwt_unix.sleep (line 31 column 9)
5151
Lwt_unix.Timeout (line 37 column 15)
5252
Lwt_unix.with_timeout (line 35 column 16)
53-
lib/test.ml: (177 occurrences)
53+
lib/test.ml: (179 occurrences)
5454
Lwt (line 36 column 12)
5555
Lwt (line 55 column 18)
5656
Lwt (line 64 column 13)
@@ -145,6 +145,8 @@ Make a writable directory tree:
145145
Lwt.Sleep (line 148 column 5)
146146
Lwt.Sleep (line 178 column 9)
147147
Lwt.state (line 145 column 9)
148+
Lwt.wrap (line 189 column 3)
149+
Lwt.wrap (line 191 column 9)
148150
Lwt.pause (line 114 column 9)
149151
Lwt.(>>=) (line 32 column 3)
150152
Lwt.(>>=) (line 33 column 27)
@@ -663,6 +665,12 @@ Make a writable directory tree:
663665
let _f () : unit = () in
664666
let _f (x : unit Promise.t) = x in
665667
()
668+
669+
let _ =
670+
let f () = () in
671+
f ()
672+
673+
let _ = (fun () -> ()) ()
666674

667675
$ cat lib/test.mli
668676
open Eio.Std

test/lwt_to_direct_style/to_direct_style.t/src/lib/test.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,9 @@ let _ =
183183
let _f () : unit Lwt.t = Lwt.return_unit in
184184
let _f (x : unit Lwt.t) = x in
185185
()
186+
187+
let _ =
188+
let f () = () in
189+
Lwt.wrap f
190+
191+
let _ = Lwt.wrap (fun () -> ())

0 commit comments

Comments
 (0)