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

Reformatting multiple array index operators (v6 style) adds spaces that are invalid #2151

Closed
2 of 3 tasks
richardcox13 opened this issue Mar 11, 2022 · 5 comments · Fixed by #2163
Closed
2 of 3 tasks

Comments

@richardcox13
Copy link

richardcox13 commented Mar 11, 2022

Issue created from fantomas-online

Code

let a = Array.create 10 -1
let b = Array.create 10 a

printfn "%d -> %d" a[0] (b[0][0])

Result

let a = Array.create 10 -1
let b = Array.create 10 a

printfn "%d -> %d" a[0] (b [ 0 ] [ 0 ])

Problem description

See above for the simplest repro I could come up with (real case had expressions for the indexes. Note using pre-v6 indexing (.[…]) works.

Extra information

  • The formatted result breaks by code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.

Options

Fantomas master branch at 2022-03-11T15:23:45Z - 1531c68

Default Fantomas configuration

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

@richardcox13 richardcox13 changed the title Reformatting multiple array index operators (v6 style) adds spaces that are invali<Insert meaningful title> Reformatting multiple array index operators (v6 style) adds spaces that are invalid Mar 11, 2022
@nojaf
Copy link
Contributor

nojaf commented Mar 12, 2022

Hello Richard, thank you for creating this issue.
The new index syntax in F# 6 is not fully supported yet in Fantomas.

To fix this, I believe we need to extend:

// expr1[expr2]
// ref: https://github.com/fsharp/fslang-design/blob/main/FSharp-6.0/FS-1110-index-syntax.md
let (|IndexWithoutDotExpr|_|) =
function
| SynExpr.App (ExprAtomicFlag.Atomic, false, identifierExpr, SynExpr.ArrayOrListComputed (false, indexExpr, _), _) ->
Some(identifierExpr, indexExpr)
| SynExpr.App (ExprAtomicFlag.NonAtomic,
false,
identifierExpr,
(SynExpr.ArrayOrListComputed (isArray = false; expr = indexExpr) as argExpr),
_) when (RangeHelpers.isAdjacentTo identifierExpr.Range argExpr.Range) ->
Some(identifierExpr, indexExpr)
| _ -> None

and capture the AST shape of b[0][0]

Are you interested in submitting a PR for this?

@richardcox13
Copy link
Author

Having had a brief look at that, it it somewhat beyond my current level of F# and parsing expertise. Sorry.

@richardcox13
Copy link
Author

Thanks for the fix.

@nojaf
Copy link
Contributor

nojaf commented Mar 24, 2022

I'll publish a new version tomorrow.

@richardcox13
Copy link
Author

Fix confirmed.

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

Successfully merging a pull request may close this issue.

2 participants