Skip to content

Commit

Permalink
Deprecate let%lwt at the structure item level
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed Oct 6, 2019
1 parent 1d44e3b commit 403df4a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/ppx/ppx_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,15 @@ let mapper =
default_loc := stri.pstr_loc;
match stri with
| [%stri let%lwt [%p? var] = [%e? exp]] ->
[%stri let [%p var] = Lwt_main.run [%e mapper.expr mapper exp]]
let warning =
str
("let%lwt should not be used at the module item level.\n" ^
"Replace let%lwt x = e by let x = Lwt_main.run (e)")
in
[%stri
let [%p var] =
(Lwt_main.run [@ocaml.ppwarning [%e warning]])
[%e mapper.expr mapper exp]]
[@metaloc !default_loc]

| x -> default_mapper.structure_item mapper x);
Expand Down
3 changes: 3 additions & 0 deletions test/ppx_expect/cases/run_1.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
File "run_1.ml", line 2, characters 0-26:
Warning 22: let%lwt should not be used at the module item level.
Replace let%lwt x = e by let x = Lwt_main.run (e)
4 changes: 2 additions & 2 deletions test/ppx_expect/cases/run_1.ml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
let%lwt () =
Lwt.return ()
(* On one line for error message compatibility with 4.09. *)
let%lwt () = Lwt.return ()

0 comments on commit 403df4a

Please sign in to comment.