ml-in-barcelona / jsoo-react

js_of_ocaml bindings for ReactJS. Based on ReasonReact.
https://ml-in-barcelona.github.io/jsoo-react
MIT License
138 stars 19 forks source link

ppx: fix inexistent locations on comps that return element list #110

Closed jchavarri closed 2 years ago

jchavarri commented 2 years ago

Fixes #90.

Instead of threading locations to the make function that is ultimately passed to createElement (which is what was originally triggering the error) we wrap the result of "ml_component" (the implementation provided by user) with : React.element annotation.

Then, the error happens earlier, in code that is not generated by ppx but written by user.

Tested manually (idk how to test ppx with full typed compilation 😅 ):

File "example/src/HelloWorldOCaml.ml", line 5, characters 26-38:
5 | let%component make ~foo = [React.null]
                              ^^^^^^^^^^^^
Error: This expression has type 'a list
       but an expression was expected of type React.element
File "example/src/HelloWorldOCaml.ml", line 5, characters 24-36:
5 | let%component make () = [React.null]
                            ^^^^^^^^^^^^
Error: This expression has type 'a list
       but an expression was expected of type React.element