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

Single AST node should contain trivia #1031

Closed
3 tasks
nojaf opened this issue Aug 27, 2020 · 0 comments · Fixed by #1038
Closed
3 tasks

Single AST node should contain trivia #1031

nojaf opened this issue Aug 27, 2020 · 0 comments · Fixed by #1038

Comments

@nojaf
Copy link
Contributor

nojaf commented Aug 27, 2020

Issue created from fantomas-online

Code

// This file is automatically generated by FAKE
// This file is needed for IDE support only
#if !FAKE
#load "intellisense_lazy.fsx"
#endif

Error

System.ArgumentException: The input sequence was empty. (Parameter 'list')
   at Fantomas.Trivia.findLastNode(FSharpList`1 nodes) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Trivia.fs:line 61
   at Fantomas.Trivia.addTriviaToTriviaNode(FSharpFunc`2 triviaBetweenAttributeAndParentBinding, Boolean hasAnonModulesAndOpenStatements, Int32 startOfSourceCode, FSharpList`1 triviaNodes, Trivia trivia) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Trivia.fs:line 381
   at Fantomas.Trivia.collectTrivia@422-1.Invoke(FSharpList`1 triviaNodes, Trivia trivia) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Trivia.fs:line 414
   at Microsoft.FSharp.Collections.ListModule.Fold[T,TState](FSharpFunc`2 folder, TState state, FSharpList`1 list) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\list.fs:line 222
   at Fantomas.Trivia.collectTrivia(FSharpList`1 tokens, Int32 lineCount, ParsedInput ast)
   at Fantomas.Context.Context.Create(FormatConfig config, FSharpList`1 defines, String content, FSharpOption`1 maybeAst)
   at Fantomas.CodeFormatterImpl.formatWith(ParsedInput ast, FSharpList`1 defines, FormatContext formatContext, FormatConfig config) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/CodeFormatterImpl.fs:line 395
   at Fantomas.CodeFormatterImpl.format@412-1.Invoke(Tuple`2[] _arg1) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/CodeFormatterImpl.fs:line 414
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, FSharpFunc`2 userCode, b result1) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 416
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in F:\workspace\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 109

Problem description

Bug in Trivia.fs

let private findLastNode (nodes: TriviaNodeAssigner list) : TriviaNodeAssigner option =
    match nodes with
    | [] -> None
    | nodes ->
        nodes
        |> List.filter isMainNodeButNotAnonModule
        |> List.maxBy (fun tn -> tn.Range.EndLine)
        |> Some

where there is only one trivia node.

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 Master at 08/27/2020 15:33:58 - 5d3a411

Default Fantomas configuration

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

Successfully merging a pull request may close this issue.

1 participant