reasonml / reason

Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems
http://reasonml.github.io
MIT License
10.12k stars 428 forks source link

"Assertion failed" when adding type definition #2587

Closed rolandpeelen closed 4 years ago

rolandpeelen commented 4 years ago

Hi!

I ran into some strange behaviour earlier today. Given the following type definition:

type segment = {
  key: string,
  title: string,
  component: React.element,
};

And the following component:

[@react.component]
 let make = (segments) => {
      segments
      ->Belt.Array.map(segment => {
          <p key={segment.key}> segment.title->React.string </p>
        })
      ->React.array
};

When I change:

 let make = (segments) => {

to

 let make = (segments: array(segment)) => {

I get the following error:

Fatal error: exception File "typecore.ml", line 2799, characters 6-12: Assertion failed

Version: BuckleScript 7.3.2 ( Using OCaml:4.06.1+BS )

rolandpeelen commented 4 years ago

Actually;

When I change it to a named parameter, it compiles;

 let make = (~segments: array(segment)) => {

I suspect this has something to do with the [@react.component] decorator expecting named parameters. As when I remove that and the ~, it compiles as well. The error message isn't particularly clear though.