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

renaming fields in inline records doesn't work when destructuring #6438

Closed
tsnobip opened this issue Oct 13, 2023 · 2 comments
Closed

renaming fields in inline records doesn't work when destructuring #6438

tsnobip opened this issue Oct 13, 2023 · 2 comments
Labels

Comments

@tsnobip
Copy link
Contributor

tsnobip commented Oct 13, 2023

thanks to #6391, it's now possible to rename fields of inline records:

type t = Foo({ @as("renamed") name: string, age: int}) | Bar
let foo = Foo({ name: "foo", age: 10 })

generates:

var foo = { TAG: "FOO", renamed: "foo", age: 10 }

But if you try to get the value then it bugs:

let getName = t =>
  switch t {
  | Bar => "bar"
  | Foo({name}) => name
  }

generates:

function getName(t) {
  if (typeof t !== "object") {
    return "bar";
  } else {
    return t.name; // the error is here, it should be t.renamed
  }
}
@anmonteiro
Copy link
Contributor

anmonteiro commented Oct 31, 2023

if you look at the patch that inspired @tatchi's, you can notice that it wasn't ported faithfully. Just a thought, but that might fix the issue.

melange-re/melange#732

EDIT: your example works in the melange playground, for example.

@DZakh
Copy link
Contributor

DZakh commented Oct 31, 2023

Looks like it's already fixed in the #6456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants