fsprojects / fantomas

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

Cannot determine upper or lowercase #753

Closed nojaf closed 4 years ago

nojaf commented 4 years ago

Couldn't create this issue with the online tool for some reason.

Problem when formatting:

let genSigModuleDeclList astContext node =
    match node with
    | [x] -> genSigModuleDecl astContext x

    | SigOpenL(xs, ys) ->
        let sepXsAndYs =
            match List.tryHead ys with
            | Some hs ->
                let attrs = getRangesFromAttributesFromSynModuleSigDeclaration hs
                sepNln +> sepNlnConsideringTriviaContentBeforeWithAttributes hs.Range attrs +> dumpAndContinue
            | None ->
                rep 2 sepNln

        fun ctx ->
            match ys with
            | [] -> col sepNln xs (genSigModuleDecl astContext) ctx
            | _ -> (col sepNln xs (genSigModuleDecl astContext) +> sepXsAndYs +> genSigModuleDeclList astContext ys) ctx

leads to

Exception: cannot determine if synExpr Paren
  (App
     (NonAtomic,false,
      App
        (NonAtomic,true,Ident op_PlusGreater,
         App
           (NonAtomic,false,
            App
              (NonAtomic,true,Ident op_PlusGreater,
               App
                 (NonAtomic,false,
                  App
                    (NonAtomic,false,
                     App
                       (NonAtomic,false,Ident col,Ident sepNln,
                        tmp.fsx (17,20--17,30) IsSynthetic=false),Ident xs,
                     tmp.fsx (17,20--17,33) IsSynthetic=false),
                  Paren
                    (App
                       (NonAtomic,false,Ident genSigModuleDecl,Ident astContext,
                        tmp.fsx (17,35--17,62) IsSynthetic=false),
                     tmp.fsx (17,34--17,35) IsSynthetic=false,
                     Some tmp.fsx (17,62--17,63) IsSynthetic=false,
                     tmp.fsx (17,34--17,63) IsSynthetic=false),
                  tmp.fsx (17,20--17,63) IsSynthetic=false),
               tmp.fsx (17,20--17,66) IsSynthetic=false),Ident sepXsAndYs,
            tmp.fsx (17,20--17,77) IsSynthetic=false),
         tmp.fsx (17,20--17,80) IsSynthetic=false),
      App
        (NonAtomic,false,
         App
           (NonAtomic,false,Ident genSigModuleDeclList,Ident astContext,
            tmp.fsx (17,81--17,112) IsSynthetic=false),Ident ys,
         tmp.fsx (17,81--17,115) IsSynthetic=false),
      tmp.fsx (17,20--17,115) IsSynthetic=false),
   tmp.fsx (17,19--17,20) IsSynthetic=false,
   Some tmp.fsx (17,115--17,116) IsSynthetic=false,
   tmp.fsx (17,19--17,116) IsSynthetic=false) is uppercase or lowercase 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.CodePrinter.addSpaceBeforeParensInFunCall(SynExpr functionOrMethod, SynExpr arg, Context ctx) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 52
   at Fantomas.CodePrinter.genExpr@1093-231.Invoke(Context ctx) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 1095
   at Fantomas.CodePrinter.genTrivia@2490-1.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 2490
   at Fantomas.Context.autoNlnCheck[a](FSharpFunc`2 f, FSharpFunc`2 sep, Context ctx) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 422
   at Fantomas.Context.autoNlnOrAddSep(FSharpFunc`2 f, FSharpFunc`2 sep, Context ctx) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 456
   at Fantomas.CodePrinter.breakNln@442-9.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 442
   at Fantomas.Context.atIndentLevel@192-6.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 192
   at Fantomas.Context.atIndentLevel(Boolean alsoSetIndent, Int32 level, FSharpFunc`2 f, Context ctx) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 193
   at Fantomas.CodePrinter.genTrivia@2490-1.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 2490
   at Fantomas.Context.col[T](FSharpFunc`2 f', IEnumerable`1 c, FSharpFunc`2 f, Context ctx) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 289
   at Fantomas.CodePrinter.genExpr@965-155.Invoke(Context ctx) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 965
   at Fantomas.Context.atIndentLevel@192-6.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 192
   at Fantomas.Context.atIndentLevel(Boolean alsoSetIndent, Int32 level, FSharpFunc`2 f, Context ctx) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 193
   at Fantomas.CodePrinter.genTrivia@2490-1.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 2490
   at Fantomas.CodePrinter.breakNln@441-4.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 441
   at Fantomas.CodePrinter.genTrivia@2490-1.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 2490
   at Fantomas.Context.atIndentLevel@192-6.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 192
   at Fantomas.Context.atIndentLevel(Boolean alsoSetIndent, Int32 level, FSharpFunc`2 f, Context ctx) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 193
   at Fantomas.CodePrinter.genTrivia@2490-1.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 2490
   at Fantomas.CodePrinter.breakNln@441-4.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 441
   at Fantomas.Context.atIndentLevel@192-6.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 192
   at Fantomas.Context.atIndentLevel(Boolean alsoSetIndent, Int32 level, FSharpFunc`2 f, Context ctx) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 193
   at Fantomas.CodePrinter.genTrivia@2490-1.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 2490
   at Fantomas.Context.col[T](FSharpFunc`2 f', IEnumerable`1 c, FSharpFunc`2 f, Context ctx) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 289
   at Fantomas.CodePrinter.genExpr@965-155.Invoke(Context ctx) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 965
   at Fantomas.Context.atIndentLevel@192-6.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 192
   at Fantomas.Context.atIndentLevel(Boolean alsoSetIndent, Int32 level, FSharpFunc`2 f, Context ctx) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 193
   at Fantomas.CodePrinter.genTrivia@2490-1.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 2490
   at Fantomas.Context.futureNlnCheckMem(FSharpFunc`2 f, Context ctx) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 429
   at Fantomas.Context.futureNlnCheck(FSharpFunc`2 f, Context ctx) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 433
   at Fantomas.CodePrinter.genExprSepEqPrependType(FSharpFunc`2 genPat, ASTContext astContext, FSharpFunc`2 prefix, SynPat pat, SynExpr e, Context ctx) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 469
   at Fantomas.CodePrinter.genTrivia@2490-1.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 2490
   at Fantomas.CodePrinter.genTrivia@2490-1.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 2490
   at Fantomas.CodePrinter.genTrivia@2490-1.Invoke(Context x) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 2490
   at Fantomas.Context.col[T](FSharpFunc`2 f', IEnumerable`1 c, FSharpFunc`2 f, Context ctx) in /build/.deps/fantomas/src/Fantomas/Context.fs:line 289
   at Fantomas.CodePrinter.genImpFile@90-6.Invoke(Context ctx) in /build/.deps/fantomas/src/Fantomas/CodePrinter.fs:line 90
   at Fantomas.CodeFormatterImpl.formatWith(ParsedInput ast, FSharpList`1 defines, FormatContext formatContext, FormatConfig config) in /build/.deps/fantomas/src/Fantomas/CodeFormatterImpl.fs:line 392
   at Fantomas.CodeFormatterImpl.format@408-1.Invoke(Tuple`2[] _arg1) in /build/.deps/fantomas/src/Fantomas/CodeFormatterImpl.fs:line 410
   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

Default settings, latest on master branch.

nojaf commented 4 years ago

Found while trying #666