Skip to content

Cons pattern in let bindings is converted to invalid code #1996

Closed
@clkbug

Description

Issue created from fantomas-online

Code

let x::y = [0]

Result

let (::) x, y = [ 0 ]

Problem description

After formatting, fantomas output the following error:

The following exception occurs while formatting stdin: Fantomas.FormatConfig+FormatException: Formatted content is not valid F# code
   at Fantomas.Extras.FakeHelpers.formatContentInternalAsync@95-5.Invoke(Boolean _arg2) in C:\Users\fverdonck\Projects\fantomas\src\Fantomas.Extras\FakeHelpers.fs:line 96
   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 Fantomas.CodeFormatterImpl.isValidFSharpCode@377-7.Invoke(AsyncActivation`1 ctxt) in C:\Users\fverdonck\Projects\fantomas\src\Fantomas\CodeFormatterImpl.fs:line 377
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104
--- End of stack trace from previous location ---
   at Microsoft.FSharp.Control.AsyncResult`1.Commit() in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 337
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronouslyInCurrentThread[a](CancellationToken cancellationToken, FSharpAsync`1 computation) in D:\workspace\_work\1\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 D:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 878
   at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 1142
   at Program.processSourceString(Boolean isFsiFile, String s, FSharpChoice`2 tw, FormatConfig config) in C:\Users\fverdonck\Projects\fantomas\src\Fantomas.CoreGlobalTool\Program.fs:line 114
   at Program.stringToFile@346(Boolean force, Boolean profile, String s, String outFile, FormatConfig config) in C:\Users\fverdonck\Projects\fantomas\src\Fantomas.CoreGlobalTool\Program.fs:line 358
Formatted content is not valid F# code

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 12/04/2021 18:09:39 - 9e35634

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?

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions