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

in is removed from binding when PreserveEndOfLine is true #340

Closed
auduchinok opened this issue Oct 24, 2018 · 4 comments · Fixed by #1157
Closed

in is removed from binding when PreserveEndOfLine is true #340

auduchinok opened this issue Oct 24, 2018 · 4 comments · Fixed by #1157

Comments

@auduchinok
Copy link
Contributor

let x = 123 in ()

is being formatted to

let x = 123()
@nojaf
Copy link
Contributor

nojaf commented Oct 27, 2018

Related:

let f () = 
  let x = 1 in   // the "in" keyword is available in F#
    let y = 2 in 
      x + y

gets formatted to

let f() =
    let x = 1
     // the "in" keyword is available in F#
     let y = 2
    x + y

Code is still valid, but the in keyword is lost.

@jindraivanek
Copy link
Contributor

@nojaf I think removing in on EOL is fine because it is just unnecessary.

However this snippet shows other bug(s) related to comment

  • bad indent of line let y = 2 - leads to invalid code
  • comment on EOL moved to separate line

with comment

without comment

@nojaf
Copy link
Contributor

nojaf commented Oct 29, 2018

Ok, good to know that the comment caused the bad indent.
Something is going wrong in TokenMatcher.

When PreserveEndOfLine is true the comment is on the correct line.

let f() =
  let x = 1  // the "in" keyword is available in F#
    let y = 2
      x + y

Indentation is not correct though.

@yuriyostapenko
Copy link

This doesn't seem to be fixed. At least for me in is being removed by 2.9.2.0.
Sometimes that in can indeed be omitted, other times it is actually required.
For example, given original

let x = List.singleton <|
        let item = "text" in
        item

if it is processed with --preserveEOL, it will strip in, but the code is at least still valid:

let x = List.singleton <|
        let item = "text"
        item

however, without preserve the output is invalid F# (and subsequent fantomas runs will throw when parsing):

let x =
    List.singleton <| let item = "text"
                      item

The compiler error is FS0010 Unexpected identifier in expression. Expected 'in' or other token.

@nojaf nojaf reopened this Jul 23, 2019
nojaf added a commit to nojaf/fantomas that referenced this issue Sep 25, 2020
nojaf added a commit that referenced this issue Sep 25, 2020
* WIP preserve in keyword.

* Preserve in keyword. Fixes #340.

* Add regression test for #1114.

* Format LetBindingTests.fs

* Add regression test for #1032.
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.

4 participants