fsprojects / fantomas

FSharp source code formatter
https://fsprojects.github.io/fantomas
Other
758 stars 189 forks source link

Using `--check` gives error "todo WhileBang" #3019

Closed abelbraaksma closed 6 months ago

abelbraaksma commented 6 months ago

Issue created from fantomas-online

Code

let f() = task {
    return true
}

let g() = task {
    while! f() do printfn "testing testing"
}

Result (note: this is expected!)

let f () = task { return true }

let g () =
    task {
        while! f () do
            printfn "testing testing"
    }

Problem description

Having something like the above, actually prevents the formatting and when running:

dotnet fantomas . --check

raises the following exception:

error: Failed to format .\src\FSharp.Control.TaskSeq\TaskSeqInternal.fs: System.Exception: todo for WhileBang
  (Yes (656,20--656,44),
   App
     (Atomic, false,
      LongIdent
        (false,
         SynLongIdent ([e; MoveNextAsync], [(656,28--656,29)], [None; None]),
         None, (656,27--656,42)), Const (Unit, (656,42--656,44)),
      (656,27--656,44)),
   YieldOrReturn
     ((true, false),
      LongIdent
        (false, SynLongIdent ([e; Current], [(657,31--657,32)], [None; None]),
         None, (657,30--657,39)), (657,24--657,39)), (656,20--657,39))
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1439.Invoke(String message) in D:\a\_work\1\s\src\fsharp\FSharp.Core\printf.fs:line 1439
   at Fantomas.Core.ASTTransformer.collectComputationExpressionStatements(CreationAide creationAide, SynExpr e, FSharpFunc`2 finalContinuation) in /_//src/Fantomas.Core/ASTTransformer.fs:line 345
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide creationAide, SynExpr e) in /_//src/Fantomas.Core/ASTTransformer.fs:line 1123
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide creationAide, SynExpr e) in /_//src/Fantomas.Core/ASTTransformer.fs:line 1108
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide creationAide, SynExpr e) in /_//src/Fantomas.Core/ASTTransformer.fs:line 1384
   at Fantomas.Core.ASTTransformer.mkSynMatchClause(CreationAide creationAide, SynMatchClause _arg4) in /_//src/Fantomas.Core/ASTTransformer.fs:line 376
   at Fantomas.Core.ASTTransformer.mkExpr@1147-8.Invoke(SynMatchClause arg10@)
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in D:\a\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 246
   at Microsoft.FSharp.Collections.ListModule.Map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 list) in D:\a\_work\1\s\src\fsharp\FSharp.Core\list.fs:line 74
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide creationAide, SynExpr e) in /_//src/Fantomas.Core/ASTTransformer.fs:line 1143
   at Fantomas.Core.ASTTransformer.collectComputationExpressionStatements(CreationAide creationAide, SynExpr e, FSharpFunc`2 finalContinuation) in /_//src/Fantomas.Core/ASTTransformer.fs:line 345
   at Fantomas.Core.ASTTransformer.mkExpr(CreationAide creationAide, SynExpr e) in /_//src/Fantomas.Core/ASTTransformer.fs:line 1123
   at Fantomas.Core.ASTTransformer.mkBinding(CreationAide creationAide, SynBinding _arg7) in /_//src/Fantomas.Core/ASTTransformer.fs:line 1810
   at Fantomas.Core.ASTTransformer.mkModuleDecl(CreationAide creationAide, SynModuleDecl decl) in /_//src/Fantomas.Core/ASTTransformer.fs:line 1971
   at Fantomas.Core.ASTTransformer.mkModuleDecls@3074-5.Invoke(FSharpList`1 nodes) in /_//src/Fantomas.Core/ASTTransformer.fs:line 3074
   at Fantomas.Core.ASTTransformer.mkModuleDecl(CreationAide creationAide, SynModuleDecl decl) in /_//src/Fantomas.Core/ASTTransformer.fs:line 1982
   at Fantomas.Core.ASTTransformer.mkModuleDecls@3074-5.Invoke(FSharpList`1 nodes) in /_//src/Fantomas.Core/ASTTransformer.fs:line 3074
   at Fantomas.Core.ASTTransformer.mkModuleOrNamespace(CreationAide creationAide, SynModuleOrNamespace mn) in /_//src/Fantomas.Core/ASTTransformer.fs:line 3139
   at Fantomas.Core.ASTTransformer.mds@3149.Invoke(SynModuleOrNamespace mn)
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in D:\a\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 244
   at Microsoft.FSharp.Collections.ListModule.Map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 list) in D:\a\_work\1\s\src\fsharp\FSharp.Core\list.fs:line 74
   at Fantomas.Core.ASTTransformer.mkImplFile(CreationAide creationAide, ParsedImplFileInput _arg15, Range m) in /_//src/Fantomas.Core/ASTTransformer.fs:line 3149
   at Fantomas.Core.ASTTransformer.mkOak(FSharpOption`1 sourceText, ParsedInput ast) in /_//src/Fantomas.Core/ASTTransformer.fs:line 3574
   at Fantomas.Core.CodeFormatterImpl.formatAST(ParsedInput ast, FSharpOption`1 sourceText, FormatConfig config, FSharpOption`1 cursor) in /_//src/Fantomas.Core/CodeFormatterImpl.fs:line 66
   at Fantomas.Core.CodeFormatterImpl.formatDocument@89-3.Invoke(Unit unitVar) in /_//src/Fantomas.Core/CodeFormatterImpl.fs:line 89
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult](AsyncActivation`1 ctxt, TResult result1, FSharpFunc`2 part2) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 446
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104
.\src\FSharp.Control.TaskSeq\TaskSeqInternal.fs needs formatting

I wonder if the "todo" can be ignored somehow. It also seems like work has been done already, as the online tool shows it is formatted without error, so maybe I just have to be patient (but reporting anyway in case someone else encounters this).

Appreciate all the good work as always!!! It is also sooo much faster than, say, a year ago!

Extra information

Live example: https://github.com/fsprojects/FSharp.Control.TaskSeq/actions/runs/7256774972/job/19769562682?pr=209

nojaf commented 6 months ago

Hi there,

'6.2.3 does not support while!, it was introduced in https://github.com/fsprojects/fantomas/blob/main/CHANGELOG.md#630-alpha-002---2023-11-07

abelbraaksma commented 6 months ago

Great stuff! I missed it somehow in the changelog. I'll wait for next version :).

dawedawe commented 6 months ago

Great stuff! I missed it somehow in the changelog. I'll wait for next version :).

Or give the alpha a spin ;) You will most likely find it very stable already.

abelbraaksma commented 6 months ago

I thought about that, but I couldn't find docs how to download the alpha in CI (i.e., dotnet tools update does not seem to pick up alpha versions, even if I specify them). @dawedawe do you know how? And/or where there's instruction to do so?

abelbraaksma commented 6 months ago

I would need to update these lines somehow, I guess, or the manifest file: https://github.com/fsprojects/FSharp.Control.TaskSeq/blob/b08c257e5513b9dcc700dc55740858b96f2d7570/.github/workflows/build.yaml#L6

dawedawe commented 6 months ago

What happens if you do a dotnet tool update fantomas --prerelease ? That should give you a "version": "6.3.0-alpha-004", inside of the manifest.

abelbraaksma commented 6 months ago

Ah, that "just works", awesome! (online there was the suggestion to use --version "*-alpha*" which did not work for me and I didn't look beyond that).

Thanks for the help 🙇.

bartelink commented 6 months ago

small aside - if you use the format 6.3.0-alpha.4, i.e. with a dot instead of a dash, each piece between periods is treated as a number from the point of view of sorting and hence doesn't need prefixing (yes, there are stone age versions of nuget that don't respect that, but they are long gone.)

nojaf commented 6 months ago

No thanks