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

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

Closed
2 of 4 tasks
josh-degraw opened this issue Mar 23, 2021 · 1 comment · Fixed by #1539
Closed
2 of 4 tasks

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

josh-degraw opened this issue Mar 23, 2021 · 1 comment · Fixed by #1539

Comments

@josh-degraw
Copy link
Contributor

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

  • The formatted result breaks by code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.
  • The formatter fails to process the input file

Options

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

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
Copy link
Contributor

nojaf commented Mar 26, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants