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

A comment before an anonymous function gets swallowed up #1190

Closed
1 of 3 tasks
naartjie opened this issue Oct 11, 2020 · 2 comments · Fixed by #1582
Closed
1 of 3 tasks

A comment before an anonymous function gets swallowed up #1190

naartjie opened this issue Oct 11, 2020 · 2 comments · Fixed by #1582

Comments

@naartjie
Copy link

naartjie commented Oct 11, 2020

Issue created from fantomas-online

Code

(   
    (* comment before gets swallowed *)
    fun x -> x * 42
)

(
    fun x -> x * 42
    (* comment after is OK *)
)

(   (* comment on first line is OK too *)
    fun x -> x * 42
)

Result

(fun x -> x * 42)

(fun x ->
    x * 42 (* comment after is OK *)
    )

( (* comment on first line is OK too *) fun x -> x * 42)

Problem description

A comment above/before an anonymous function is getting dropped from the formatted output. This also happens if you use // for a line comment instead of the (* *) block comment syntax.

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 10/02/2020 17:06:53 - 31305c2

Default Fantomas configuration

Possibly related issues

#1179 #1172 #932

@nojaf
Copy link
Contributor

nojaf commented Oct 16, 2020

Hello @naartjie, I'm in the process of writing some more 'getting started' content. See #1195.

As for this problem, it is a trivia bug.
See online tool.

Fantomas assigns the block comment to a SynExpr.Lambda node. And in CodePrinter.fs we need to call genTrivia or variant in order that the comment gets restored.

image

In CodePrinter I believe it is not printed around here.
Call it a gut feeling.

@naartjie
Copy link
Author

naartjie commented Apr 3, 2021

Thank you for fixing this 🚀 🚀

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