Skip to content

type specialisation for options does not work with externals #4930

@bobzhang

Description

@bobzhang
let f ?x y = 
  (match  x with 
  | None -> 1 
  | Some (_:string) -> 2 ) + y


type t = {
  y : int [@optional]
}[@@deriving abstract]


let u ?y () = t ?y ()
function f(x, y) {
  return (
          x !== undefined ? 2 : 1
        ) + y | 0;
}

function u(y, param) {
  var tmp = {};
  if (y !== undefined) {
    tmp.y = Caml_option.valFromOption(y);
  }
  return tmp;
}

The second one does not get specialized.
Raised here https://forum.rescript-lang.org/t/how-can-i-get-rid-of-the-runtime-libraries/1001/2
Code snippet:

[@react.component]
let make = (
  ~href: string,
  ~className: option(string)=?,
  ~onClick: option(clickHandler)=?,
  ~children: React.element,
) => {
  let onClick = Belt.Option.getWithDefault(onClick, makeDefaultClickHandler(href));

  <a href onClick ?className> children </a>
}

Expanded code:

external makeProps :
  href:string ->
    ?className:string ->
      ?onClick:clickHandler ->
        children:React.element ->
          ?key:string ->
            unit ->
              <
                href: string  ;className: string option  ;onClick: clickHandler
                                                                    option  ;
                children: React.element   >  Js.t = ""

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions