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

formatting of modules with explicitly annotated type inside a function yields syntactically incorrect result #6212

Closed
woeps opened this issue Apr 26, 2023 · 1 comment · Fixed by #6239
Labels
Milestone

Comments

@woeps
Copy link

woeps commented Apr 26, 2023

Using rescript format on the following code yields syntactically incorrect result:

// compiles successfully
module type T = {
  let f: string => string
}

let g = (x: string) => {
  module M: T = {
    let f = s => s ++ s
  }
  x->M.f
}

will be formatted to:

// compilation fails with syntax error
module type T = {
  let f: string => string
}

let g = (x: string) => {
  module M = {
    let f = s => s ++ s
  }: T // <-- Note the type annotation was moved here~
  x->M.f
}

Afaik this issue is present in all versions of rescript (9.* & 10.*).

Repro available as a repository at https://github.com/woeps/rescript-formatting-issue-repro or at the playground..

While I understand this is not ideal code in most cases, I believe formatting should always yield a syntactically correct result.


Note: If the module (with type signature) is not inside a function, formatting works as expected:

// compiles successfully and won't be reformatted
module type T = {
  let f: string => string
}

module M: T = {
  let f = s => s ++ s
}

above example at the Playground

@cristianoc cristianoc added the bug label Apr 27, 2023
@cristianoc cristianoc added this to the v11.0 milestone Apr 27, 2023
@cristianoc
Copy link
Collaborator

Definitely a bug, likely with the pretty printer.

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

Successfully merging a pull request may close this issue.

2 participants