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

Rescript formatting unstable and producing semantic deviations for inline functions in pipe chains #6749

Open
5 tasks done
mrmurphy opened this issue May 3, 2024 · 1 comment

Comments

@mrmurphy
Copy link

mrmurphy commented May 3, 2024

Hi there! I'm upgrading my codebase to Rescript 11 and ran into an old file that has its semantic meaning changed when the formatter is run on it multiple times.

Original snippet:

let setProcessedRevocationForExParticipants = (
  ~tx=?,
  ~journalGID: GID.t,
  ~userIds: array<string>,
  ~timestamp: Js.Date.t,
  (),
) => {
  open DB2.SharedJournals
  update({"processed_revocation_at": timestamp})
  ->whereEq("journal_gid", journalGID->GID.toString)
  ->where(isNotNull("revoked_at"))
  ->where(isNull("processed_revocation_at"))
  ->(a => userIds->Js.Array2.length > 0 ? a->where(not_(in_(~col="with_user", userIds))) : a)
  ->DB.Main.Run.ignore(~tx?)
}

After saving the file once:

let setProcessedRevocationForExParticipants = (
  ~tx=?,
  ~journalGID: GID.t,
  ~userIds: array<string>,
  ~timestamp: Js.Date.t,
  (),
) => {
  open DB2.SharedJournals
  update({"processed_revocation_at": timestamp})
  ->whereEq("journal_gid", journalGID->GID.toString)
  ->where(isNotNull("revoked_at"))
  ->where(isNull("processed_revocation_at"))
  ->a => userIds->Js.Array2.length > 0 ? a->where(not_(in_(~col="with_user", userIds))) : a
  ->DB.Main.Run.ignore(~tx?)
}

Notice that the parens around (a => ...) have been dropped

And after another save:

let setProcessedRevocationForExParticipants = (
  ~tx=?,
  ~journalGID: GID.t,
  ~userIds: array<string>,
  ~timestamp: Js.Date.t,
  (),
) => {
  open DB2.SharedJournals
  update({"processed_revocation_at": timestamp})
  ->whereEq("journal_gid", journalGID->GID.toString)
  ->where(isNotNull("revoked_at"))
  ->where(isNull("processed_revocation_at"))
  ->(
    a =>
      userIds->Js.Array2.length > 0
        ? a->where(not_(in_(~col="with_user", userIds)))
        : a->DB.Main.Run.ignore(~tx?)
  )
}

Notice that the compiler now thinks that DB.Main.Run should be called on a directly, instead of on the result of the function that a belongs to.

Thank you for filing! Check list:

  • Is it a bug? Usage questions should often be asked in the forum instead.
  • Concise, focused, friendly issue title & description.
  • A minimal, reproducible example.
  • OS and browser versions, if relevant.
  • Is it already fixed in master? Instructions
@mrmurphy mrmurphy changed the title Rescript formatting unstable and producing semantic deviations Rescript formatting unstable and producing semantic deviations for inline functions in pipe chains May 3, 2024
@mrmurphy
Copy link
Author

mrmurphy commented May 3, 2024

Workaround for now is to extract that inline function into its own variable

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

1 participant