Skip to content

Allow records in js objects #4922

@bobzhang

Description

@bobzhang
type t = {
  y : int
}
let x = {"x" : { y : 3}}

let u : t = x["x"]

Here the nested record is still interpreted as structural type.
It used to work this way for two reasons:

  • record was compiled as an array
  • the ocaml syntax is quite heavy for nested structual objects, so I chose to inherit, otherwise it would be as below which is too verbose
[%obj{x = [%obj{y = 3}]]

To fix this, the work may be done on my side (the internal ppx), for rescript syntax, the structural objects will not be inherited.
This would be a breaking change for rescript syntax (in a good way).

Note this is not an issue in type space, since object types have different syntax < x : int> vs {x:int}
Question: does it make sense to change the semantics of ocaml syntax as well, not inherit the structual property inside the nested objects?

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