fantomas icon indicating copy to clipboard operation
fantomas copied to clipboard

code using mix of #if and parentheses doesn't parse after formatting

Open nojaf opened this issue 4 years ago • 1 comments

Issue created from fantomas-online

Code

module M

let f() =
                if a then (
#if DEBUG
                    if b then Console.Write("ErrorFlag... ")
#endif
#if DEBUG
                    if b then c
#endif
                    ()
                ) 

Error

Fantomas.FormatConfig+FormatException: Parsing failed with errors: [|tmp.fsx (12,9)-(12,10) parse error Unexpected symbol '(' in expression;
  tmp.fsx (12,11)-(12,12) parse error Unexpected symbol ')' in if/then/else expression. Expected incomplete structured construct at or before this point or other token.;
  tmp.fsx (13,1)-(13,1) parse error Incomplete structured construct at or before this point in binding. Expected incomplete structured construct at or before this point or other token.;
  tmp.fsx (3,1)-(3,4) parse error Incomplete value or function definition. If this is in an expression, the body of the expression must be indented to the same column as the 'let' keyword.;
  tmp.fsx (13,1)-(13,1) parse error Incomplete structured construct at or before this point in implementation file|]
And options: { SourceFiles = [|"tmp.fsx"|]
  ConditionalCompilationDefines = ["DEBUG"]
  ErrorSeverityOptions = { WarnLevel = 3
                           GlobalWarnAsError = false
                           WarnOff = []
                           WarnOn = []
                           WarnAsError = []
                           WarnAsWarn = [] }
  LangVersionText = "preview"
  IsInteractive = false
  LightSyntax = None
  CompilingFsLib = false
  IsExe = true }
   at [email protected](FSharpParseFileResults _arg2) in /app/.deps/fantomas/src/Fantomas/CodeFormatterImpl.fs:line 81
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 464
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104
--- End of stack trace from previous location ---
   at [email protected](Unit unitVar0) in /app/src/server/FantomasOnline.Shared/Http.fs:line 98
   at Ply.TplPrimitives.AwaitableContinuation`3.Invoke(Unit r)

Problem description

Please describe here the Fantomas problem you encountered. Check out our Contribution Guidelines.

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 4.6 branch at 11/24/2021 18:43:36 - 9eb1365627a87929af770bd60baed8be76e61103

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?

nojaf avatar Dec 02 '21 16:12 nojaf

Formatted output:

module M

let f () =
    if a then
        (
#if DEBUG
         if b then Console.Write("ErrorFlag... ")
#endif
#if DEBUG
         if b then c
#endif
        ())

nojaf avatar Dec 02 '21 16:12 nojaf