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

Error when combining #if directive with async block and let #576

Closed
theimowski opened this issue Nov 28, 2019 · 2 comments · Fixed by #600
Closed

Error when combining #if directive with async block and let #576

theimowski opened this issue Nov 28, 2019 · 2 comments · Fixed by #600

Comments

@theimowski
Copy link
Member

Issue created from fantomas-ui

Fantomas fails to format if given a conditional #if block in conjunction with async block and a let binding within (works ok when I remove let from async)

Code

#if TEST
let f () =
    async {
        let x = 2
        return x
    }
#endif

Error

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. Stack Trace:    at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1637.Invoke(String message) in E:\A\_work\130\s\src\fsharp\FSharp.Core\printf.fs:line 1637
   at Fantomas.String.merge(String a, String b)
   at Fantomas.CodeFormatterImpl.merged@415.Invoke(String a, String b)
   at Microsoft.FSharp.Collections.ListModule.Fold[T,TState](FSharpFunc`2 folder, TState state, FSharpList`1 list) in E:\A\_work\130\s\src\fsharp\FSharp.Core\list.fs:line 221
   at Microsoft.FSharp.Collections.ListModule.Reduce[T](FSharpFunc`2 reduction, FSharpList`1 list) in E:\A\_work\130\s\src\fsharp\FSharp.Core\list.fs:line 233
   at Fantomas.CodeFormatterImpl.format@405-1.Invoke(Tuple`2[] _arg1)
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, FSharpFunc`2 userCode, b result1) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 416
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 109
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.FSharp.Control.AsyncResult`1.Commit() in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 349
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronouslyInCurrentThread[a](CancellationToken cancellationToken, FSharpAsync`1 computation) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 870
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync`1 computation, FSharpOption`1 timeout) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 890
   at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 1153
   at Server.Result.attempt[a](FSharpFunc`2 f) in /build/src/Server/Server.fs:line 24

Options

Fantomas 3.0.0

Name Value
IndentOnTryWith false
IndentSpaceNum 4
KeepNewlineAfter false
PageWidth 120
ReorderOpenDeclaration false
SemicolonAtEndOfLine false
SpaceAfterComma true
SpaceAfterSemicolon true
SpaceAroundDelimiter true
SpaceBeforeArgument true
SpaceBeforeColon false
StrictMode false
@nojaf
Copy link
Contributor

nojaf commented Nov 28, 2019

I think the problem is more related to having only code within an #if directive.
Nevertheless thanks for reporting this bug.

@theimowski
Copy link
Member Author

If you remove the let binding, it works perfectly fine

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.

2 participants