Skip to content

Commit

Permalink
feat(ppx): print unprocessed alert when finding uncurried attribute (
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro authored Nov 30, 2023
1 parent 28565d3 commit e883821
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ Unreleased
- Introduce an `unprocessed` alert to detect unprocessed Melange code, hinting
users to preprocess with `melange.ppx`
([#911](https://github.com/melange-re/melange/pull/911),
[#945](https://github.com/melange-re/melange/pull/945))
[#945](https://github.com/melange-re/melange/pull/945),
[#947](https://github.com/melange-re/melange/pull/947))

2.1.0 2023-10-22
---------------
Expand Down
23 changes: 22 additions & 1 deletion jscomp/core/mel_ast_invariant.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,24 @@ let emit_external_warnings : Ast_iterator.iterator =
{
Warnings.kind = "unprocessed";
message =
"[%@mel.*] attributes found in external declaration. Did you forget \
"`[@mel.*]' attributes found in external declaration. Did you forget \
to preprocess with `melange.ppx'?";
def = Location.none;
use = loc;
}
in
let print_unprocessed_uncurried_alert ~loc =
Location.prerr_alert loc
{
Warnings.kind = "unprocessed";
message =
"Found uncurried (`[@u]') attribute. Did you forget to preprocess \
with `melange.ppx'?";
def = Location.none;
use = loc;
}
in

let super = Ast_iterator.default_iterator in
{
super with
Expand All @@ -89,6 +101,15 @@ let emit_external_warnings : Ast_iterator.iterator =
| _ -> super.signature_item self sigi);
expr =
(fun self a ->
(match
List.find_opt
~f:(fun { Parsetree.attr_name = { txt; _ }; _ } -> txt = "u")
a.pexp_attributes
with
| Some { attr_name = { loc; _ }; _ } ->
print_unprocessed_uncurried_alert ~loc
| None -> ());

match a.pexp_desc with
| Pexp_constant const -> check_constant a.pexp_loc `expr const
| Pexp_apply ({ pexp_desc = Pexp_ident { txt = Lident op; loc }; _ }, _)
Expand Down
24 changes: 20 additions & 4 deletions test/blackbox-tests/unprocessed-attributes.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
File "x.mli", line 2, characters 0-67:
2 | external some_external : unit -> t = "" [@@mel.module "forgot-ppx"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alert unprocessed: [%@mel.*] attributes found in external declaration. Did you forget to preprocess with `melange.ppx'?
Alert unprocessed: `[@mel.*]' attributes found in external declaration. Did you forget to preprocess with `melange.ppx'?
File "x.ml", line 2, characters 0-67:
2 | external some_external : unit -> t = "" [@@mel.module "forgot-ppx"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alert unprocessed: [%@mel.*] attributes found in external declaration. Did you forget to preprocess with `melange.ppx'?
Alert unprocessed: `[@mel.*]' attributes found in external declaration. Did you forget to preprocess with `melange.ppx'?

$ rm x.mli
$ cat > x.ml <<EOF
> let () = ref 0 |. incr
> let () = foo##bar
Expand All @@ -37,15 +38,30 @@
File "x.ml", line 1, characters 15-17:
1 | let () = ref 0 |. incr
^^
Alert unprocessed: [%@mel.*] attributes found in external declaration. Did you forget to preprocess with `melange.ppx'?
Alert unprocessed: `[@mel.*]' attributes found in external declaration. Did you forget to preprocess with `melange.ppx'?

File "x.ml", line 2, characters 12-14:
2 | let () = foo##bar
^^
Alert unprocessed: [%@mel.*] attributes found in external declaration. Did you forget to preprocess with `melange.ppx'?
Alert unprocessed: `[@mel.*]' attributes found in external declaration. Did you forget to preprocess with `melange.ppx'?

File "x.ml", line 1, characters 15-17:
1 | let () = ref 0 |. incr
^^
Error: '|.' is not a valid value identifier.
[1]

$ cat > x.ml <<EOF
> let x = fun [@u] () -> 42
> let y = (x () [@u])
> EOF
$ dune build @melange
File "x.ml", line 1, characters 14-15:
1 | let x = fun [@u] () -> 42
^
Alert unprocessed: Found uncurried (`[@u]') attribute. Did you forget to preprocess with `melange.ppx'?

File "x.ml", line 2, characters 16-17:
2 | let y = (x () [@u])
^
Alert unprocessed: Found uncurried (`[@u]') attribute. Did you forget to preprocess with `melange.ppx'?

0 comments on commit e883821

Please sign in to comment.