fsprojects / fantomas

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

Fantomas throws an exception with custom operator (>??) #1533

Closed josh-degraw closed 3 years ago

josh-degraw commented 3 years ago

Issue created from fantomas-online

Code

// Minimal code that displays the root of the issue:
let inline (>??) x = x > x

Error

System.Exception: was not expecting token QMARK_QMARK
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1433.Invoke(String message) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\printf.fs:line 1433
   at Fantomas.TokenParser.getTriviaNodesFromTokens@1069.Invoke(Token t) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/TokenParser.fs:line 1071
   at Microsoft.FSharp.Primitives.Basics.List.mapToFreshConsTail[a,b](FSharpList`1 cons, FSharpFunc`2 f, FSharpList`1 x) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 241
   at Microsoft.FSharp.Primitives.Basics.List.map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 x) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\local.fs:line 251
   at Microsoft.FSharp.Collections.ListModule.Map[T,TResult](FSharpFunc`2 mapping, FSharpList`1 list) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\list.fs:line 75
   at Fantomas.Trivia.collectTrivia(FSharpFunc`2 mkRange, FSharpList`1 tokens, ParsedInput ast) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Trivia.fs:line 524
   at Fantomas.Context.Context.Create(FormatConfig config, FSharpList`1 defines, String fileName, FSharpList`1 hashTokens, String content, FSharpOption`1 maybeAst) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Context.fs:line 200
   at Fantomas.CodeFormatterImpl.formatWith(ParsedInput ast, FSharpList`1 defines, FSharpList`1 hashTokens, FormatContext formatContext, FormatConfig config) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/CodeFormatterImpl.fs:line 387
   at Fantomas.CodeFormatterImpl.format@401-1.Invoke(Tuple`3[] _arg1) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/CodeFormatterImpl.fs:line 403
   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 Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 104

Problem description

I have some custom operators that end in ?? (used for testing). When trying to format the file that defines these operators, fantomas throws the above exception. I've verified that it's not just the fact that the operator includes ??, because the following operators seem to not have any issues when using the online tool to test:

// No issues encountered with any of the following operators:
let inline (=??) x = //...
let inline (<>??) x = //...
let inline (<??) x = //...
let inline (>=??) x = //...
let inline (<=??) x = //...

Extra information

Options

Fantomas Master at 03/22/2021 19:47:45 - 8eec950c7d7c431bb251fc0156e405763642923c

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 commented 3 years ago

Hello Josh, thank you for reporting this issue. I was going to explain how to solve this, but the fix was rather simple so it's on the house. Please check my PR in case you ever encounter any similar problems in the future.