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

Bug: Record merging syntax with switch statement adds a semicolon instead of a comma #70

Closed
ByronBecker opened this issue Dec 17, 2022 · 4 comments · Fixed by #72
Closed

Comments

@ByronBecker
Copy link

Example case:

let person_1 = {
  name = "John";
  ageGroup = #minor";
};

let minor_permissions = { ... };
let adult_permissions = { ... };

let person_1_plus_permissions = person_1 and (
  switch(person1.ageGroup) {
    case (#minor) { minorPermissions };
    case (#adult) { adultPermissions };
  },  // prettier puts a `;` here instead of a `,`, which throws a syntax error
);

@rvanasa
Copy link
Contributor

rvanasa commented Dec 17, 2022

Strange!

It looks like there is an extraneous quotation mark in ageGroup = #minor"; (at least in the above example). Fixing that causes the code to format as expected for me (playground link).

The most likely underlying cause is that Prettier is falling back to the JavaScript formatter, which can happen if there is a plugin installation issue.

@q-uint
Copy link

q-uint commented Dec 18, 2022

(can probably be simplified)

type AgeGroup = {
  #minor;
  #adult;
};

type Person = {
  name : Text;
  ageGroup : AgeGroup;
};

type Permissions = {
  some : Text;
};

type PPerson = Person and Permissions;

let person_1 : Person = {
  name = "John";
  ageGroup = #minor;
};

func ageGroup(p : Person) : AgeGroup {
  return p.ageGroup;
};

func pperson(p : Person) : PPerson {
  {
    p and (
      switch (ageGroup(p)) {
        case (#minor) { { some = "M" } };
        case (#adult) { { some = "A" } };
      }, // ADDED? OK
    ): // ADDED? NOK
  };
};

Playground: link

@rvanasa
Copy link
Contributor

rvanasa commented Dec 18, 2022

Okay, thanks! I see what you're saying and will look into fixing this.

@rvanasa
Copy link
Contributor

rvanasa commented Dec 18, 2022

Fixed in v0.2.4!

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

Successfully merging a pull request may close this issue.

3 participants