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

Failed assertion when parsing [%bs.obj] #1222

Closed
ryb73 opened this issue Apr 17, 2017 · 3 comments
Closed

Failed assertion when parsing [%bs.obj] #1222

ryb73 opened this issue Apr 17, 2017 · 3 comments

Comments

@ryb73
Copy link

ryb73 commented Apr 17, 2017

I got the following error when running refmt with no options:

refmt: internal error, uncaught exception:
       File "src/reason_pprint_ast.ml", line 4969, characters 13-19: Assertion failed

My input file:

type pathObject =
  [%bs.obj: <
         dir : string ;
         root : string ;
         base : string ;
         name : string ;
         ext : string          
       >            
  ] 

I'm using Reason 1.13.0.

@bsansouci
Copy link
Contributor

bsansouci commented Apr 17, 2017

Hey @ryb73 I think the types here would be simply this in ocaml:

type pathObject = <
  dir : string ;
  root : string ;
  base : string ;
  name : string ;
  ext : string          
>

which actually today's syntax in Reason is:

type pathObject = {. /* The dot means it's a close object type. You can use 2 dots to mean open object type. */
  dir : string, 
  root : string, 
  base : string, 
  name : string,
  ext : string
};

What you use %bs.obj for is the literal, the value of the object:

let a: pathObject = [%bs.obj {dir: "asd"}]
/* actually we have premium syntax for those JS objects, which is the following */
let a: pathObject = {"dir": "asd"} /* notice the quotes around the key */

I'd recommend using reason-tools to look at what all those become into OCaml if that helps. Or compile to JS to see the output.

@Schmavery
Copy link
Contributor

Schmavery commented Apr 17, 2017

@bsansouci actually it should be possible to use %bs.obj for both types and values (at least in ocaml, it doesn't seem to work for reason when I try either): https://bloomberg.github.io/bucklescript/Manual.html#_create_js_objects_using_bs_obj

@chenglou
Copy link
Member

Fixed by #1659. There's a better warning for this now

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

4 participants