From 3e84cfbf10111a84dc97a9dfa3bc1fbdb65d1877 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Fri, 20 Oct 2023 17:17:41 -0700 Subject: [PATCH 1/2] test: demonstrate redundant check in reason-react-ppx --- ppx/test/optional-arg-check.t | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 ppx/test/optional-arg-check.t diff --git a/ppx/test/optional-arg-check.t b/ppx/test/optional-arg-check.t new file mode 100644 index 000000000..f9f012b3f --- /dev/null +++ b/ppx/test/optional-arg-check.t @@ -0,0 +1,34 @@ +Show the error message when an optionally labelled argument has the wrong type + + $ cat > dune-project < (lang dune 3.8) + > (using melange 0.1) + > EOF + + $ cat > dune < (melange.emit + > (target output) + > (alias mel) + > (emit_stdlib false) + > (libraries reason-react) + > (preprocess (pps melange.ppx reason-react-ppx))) + > EOF + + $ cat > x.re < module App = { + > [@react.component] + > let make = (~myProp: bool=?) => React.null; + > }; + > EOF + + $ dune build @mel + File "x.re", line 3, characters 15-27: + 3 | let make = (~myProp: bool=?) => React.null; + ^^^^^^^^^^^^ + Warning 22 [preprocessor]: react-jsx-ppx: optional argument annotations must have an explicit `option` type. Did you mean `option(bool)=?`? + File "x.re", line 3, characters 15-27: + 3 | let make = (~myProp: bool=?) => React.null; + ^^^^^^^^^^^^ + Error: This pattern matches values of type bool + but a pattern was expected which matches values of type 'a option + [1] From 47219110d6b2b1736306a40caa26fbbb80ff52d0 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Thu, 19 Oct 2023 15:56:12 -0700 Subject: [PATCH 2/2] fix: remove untrue check related to option(_) labelled props --- ppx/reason_react_ppx.ml | 23 ----------------------- ppx/test/optional-arg-check.t | 4 ---- 2 files changed, 27 deletions(-) diff --git a/ppx/reason_react_ppx.ml b/ppx/reason_react_ppx.ml index 0145766a2..c3c8bd4e0 100644 --- a/ppx/reason_react_ppx.ml +++ b/ppx/reason_react_ppx.ml @@ -639,29 +639,6 @@ let jsxMapper = default, pattern, expression ) -> - let () = - match (arg, pattern, default) with - | Optional _, { ppat_desc = Ppat_constraint (_, { ptyp_desc }) }, None -> ( - match ptyp_desc with - | Ptyp_constr ({ txt = Lident "option" }, [ _ ]) -> () - | _ -> - let currentType = - match ptyp_desc with - | Ptyp_constr ({ txt }, []) -> - String.concat "." (Longident.flatten_exn txt) - | Ptyp_constr ({ txt }, _innerTypeArgs) -> - String.concat "." (Longident.flatten_exn txt) ^ "(...)" - | _ -> "..." - in - Ocaml_common.Location.prerr_warning pattern.ppat_loc - (Preprocessor - (Printf.sprintf - "reason-react-ppx: optional argument annotations \ - must have an explicit `option` type. Did you mean \ - `option(%s)=?`?" - currentType))) - | _ -> () - in let alias = match pattern with | { ppat_desc = Ppat_alias (_, { txt }) | Ppat_var { txt } } -> txt diff --git a/ppx/test/optional-arg-check.t b/ppx/test/optional-arg-check.t index f9f012b3f..825b679ff 100644 --- a/ppx/test/optional-arg-check.t +++ b/ppx/test/optional-arg-check.t @@ -23,10 +23,6 @@ Show the error message when an optionally labelled argument has the wrong type $ dune build @mel File "x.re", line 3, characters 15-27: - 3 | let make = (~myProp: bool=?) => React.null; - ^^^^^^^^^^^^ - Warning 22 [preprocessor]: react-jsx-ppx: optional argument annotations must have an explicit `option` type. Did you mean `option(bool)=?`? - File "x.re", line 3, characters 15-27: 3 | let make = (~myProp: bool=?) => React.null; ^^^^^^^^^^^^ Error: This pattern matches values of type bool