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

Breaks float range with step-size when trailing 0 is omitted #2171

Closed
1 of 3 tasks
peterhirn opened this issue Mar 30, 2022 · 1 comment · Fixed by #2205
Closed
1 of 3 tasks

Breaks float range with step-size when trailing 0 is omitted #2171

peterhirn opened this issue Mar 30, 2022 · 1 comment · Fixed by #2205
Labels
bug (soundness) good first issue Long hanging fruit: easy issue to get your feet wet!

Comments

@peterhirn
Copy link

Issue created from fantomas-online

Code

let foo = [1. .. 0.1 .. 2.]

Result

let foo = [ 1...0.1..2. ]

Workaround

let foo = [ 1.0..0.1..2.0 ]

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-29T09:12:14Z - 8f2ab14

Default Fantomas configuration

@nojaf
Copy link
Contributor

nojaf commented Mar 30, 2022

Hello, thank you for reporting this issue.

The fix will probably need to be somewhere around:

| IndexRangeExpr (None, None) -> !- "*"
| IndexRangeExpr (Some (IndexRangeExpr (Some (ConstNumberExpr e1), Some (ConstNumberExpr e2))),
Some (ConstNumberExpr e3)) ->
genExpr astContext e1
+> !- ".."
+> genExpr astContext e2
+> !- ".."
+> genExpr astContext e3
| IndexRangeExpr (e1, e2) ->
let hasSpaces =
let rec (|AtomicExpr|_|) e =
match e with
| NegativeNumber _ -> None
| SynExpr.Ident _
| SynExpr.Const (SynConst.Int32 _, _)
| IndexRangeExpr (Some (AtomicExpr _), Some (AtomicExpr _))
| IndexFromEndExpr (AtomicExpr _) -> Some e
| _ -> None
match e1, e2 with
| Some (AtomicExpr _), None
| None, Some (AtomicExpr _)
| Some (AtomicExpr _), Some (AtomicExpr _) -> false
| _ -> true
optSingle (fun e -> genExpr astContext e +> onlyIf hasSpaces sepSpace) e1
+> !- ".."
+> optSingle (fun e -> onlyIf hasSpaces sepSpace +> genExpr astContext e) e2

Are you interested in submitting a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug (soundness) good first issue Long hanging fruit: easy issue to get your feet wet!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants