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

Exception - detect of multiple defines when define surrounds a DU member #1503

Closed
3 tasks
theimowski opened this issue Mar 5, 2021 · 2 comments
Closed
3 tasks

Comments

@theimowski
Copy link
Member

Issue created from fantomas-online

Code

type A =
  | B of int
  | C

#if DEBUG
  with
    member this.GetB =
      match this with
      | B x -> x
      | _ -> failwith "shouldn't happen"
#endif

Error

System.Exception: Fantomas is trying to format the input multiple times due to the detect of multiple defines.
There is a problem with merging all the code back togheter. Please raise an issue at https://github.com/fsprojects/fantomas/issues.
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1433.Invoke(String message) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\printf.fs:line 1433
   at Fantomas.String.merge(String a, String b) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Utils.fs:line 62
   at Microsoft.FSharp.Collections.ListModule.Fold[T,TState](FSharpFunc`2 folder, TState state, FSharpList`1 list) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\list.fs:line 222
   at Microsoft.FSharp.Collections.ListModule.Reduce[T](FSharpFunc`2 reduction, FSharpList`1 list) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\list.fs:line 234
   at Fantomas.CodeFormatterImpl.format@408-1.Invoke(Tuple`3[] _arg1) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/CodeFormatterImpl.fs:line 417
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, FSharpFunc`2 userCode, b result1) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 404
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104

Problem description

Removing the preprocessor directive fixes the isse

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 at 03/03/2021 07:40:00 - e92fa7a

    { config with
                IndentSize = 2 }

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

@nojaf
Copy link
Contributor

nojaf commented Mar 25, 2021

Thanks for your recent reports Tomasz. I've looked at all of them and none are really trivial to solve I'm afraid.
Perhaps over time, I see more opportunities to fix the others as well.

@theimowski
Copy link
Member Author

They are quite edge cases, multiple preprocessor directives probably don't help.
On a side note, I've found these type of conditionals making code harder to maintain and strive to refactor towards getting rid of them wherever possible.

nojaf added a commit to nojaf/fantomas that referenced this issue Mar 26, 2021
nojaf added a commit to nojaf/fantomas that referenced this issue Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants