Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

let%component ppx transforms type annotation incorrectly #53

Open
glennsl opened this issue Nov 13, 2019 · 0 comments
Open

let%component ppx transforms type annotation incorrectly #53

glennsl opened this issue Nov 13, 2019 · 0 comments

Comments

@glennsl
Copy link
Collaborator

glennsl commented Nov 13, 2019

Type annotations on let%component functions are transformed to apply to only the return value, not the entire function.

1. Annotation of return type

module ShouldAllowComponentProp = {
  let%component make = (~component, (), hooks): element(node) =>
    (<Div> component </Div>, hooks);
}

Transforms to:

module ShouldAllowComponentProp =
  struct
    let make =
      let brisk-component =
        Brisk_reconciler.Expert.component ~useDynamicKey:false
          "test/Components.re.ShouldAllowComponentProp.make" in
      fun ?(key= Brisk_reconciler.Key.none) ->
        fun ~component ->
          fun () ->
            brisk-component ~key
              (fun hooks ->
                 (((let brisk-component = Div.make in
                    ((brisk-component
                        ~children:(Brisk_reconciler.Expert.jsx_list
                                     [component]) ())
                      [@JSX ])), hooks) : node element))
  end

Which produces the type error:

File "test/Components.re", line 239, characters 4-35:
239 |     (<Div> component </Div>, hooks);
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This expression has type 'a * 'b
       but an expression was expected of type node element

2. Annotation of entire function type

module ShouldAllowComponentProp = {
  let%component make
    : (~key:int=?, ~component: element(node), unit) => element(node) 
    = (~component, (), hooks) =>
      (<Div> component </Div>, hooks);
}

Transforms to:

module ShouldAllowComponentProp =
  struct
    let make =
      let brisk-component =
        Brisk_reconciler.Expert.component ~useDynamicKey:false
          "test/Components.re.ShouldAllowComponentProp.make" in
      fun ?(key= Brisk_reconciler.Key.none) ->
        brisk-component ~key
          (fun ~component ->
             fun () ->
               fun hooks ->
                 ((let brisk-component = Div.make in
                   ((brisk-component
                       ~children:(Brisk_reconciler.Expert.jsx_list
                                    [component]) ())
                     [@JSX ])), hooks) : ?key:int ->
                                           component:node element ->
                                             unit -> node element)
  end

Which produces the error:

File "test/Components.re", line 240, characters 4-62:
240 |     (~component, (), hooks) => (<Div> component </Div>, hooks);
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This function should have type
         ?key:int -> component:node element -> unit -> node element
       but its first argument is labelled ~component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant