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

Support empty string as a valid key in a Js.t object #3494

Closed
nireno opened this issue Apr 13, 2019 · 6 comments
Closed

Support empty string as a valid key in a Js.t object #3494

nireno opened this issue Apr 13, 2019 · 6 comments

Comments

@nireno
Copy link

nireno commented Apr 13, 2019

Defining a Js.t object such as let obj = {"": someValue}; throws the following for me:

Fatal error: exception File "lam_methname.ml", line 135, characters 2-8: Assertion failed
File "", line 1:
Error: Error while running external preprocessor

I encountered the problem while trying to define an xstate transient transition which gives special meaning to the empty string key.

Side note: Putting the Js.t example above on the "Try Reason" website currently causes the site to completely crash.

@bobzhang
Copy link
Member

how do you access it in this case?

@nireno
Copy link
Author

nireno commented Apr 15, 2019

In this use case I don't need to read the value. The object is only used to configure xstate. But I understand the dilemma so if this is too much of an edge you can close this.

If anyone else stumbles on this, a workaround suggested was to use Js.Dict.fromArray:

let states = Js.Dict.fromArray([|
  ("", [|
    {"target": "win", "cond": "didPlayerWin"},
    {"target": "lose", "cond": "didPlayerLose"},
  |]),
|]);

@bobzhang
Copy link
Member

We should at least provide a better error message

@bobzhang
Copy link
Member

moved to reasonml/reason#2387

@bobzhang bobzhang reopened this Dec 2, 2019
@bobzhang
Copy link
Member

bobzhang commented Aug 4, 2020

The work around looks reasonable given this is a corner case

@amiralies
Copy link
Contributor

@bobzhang should we allow this since object access syntax is now x[""] ?

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

3 participants