You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Comment between a match pattern and its when guard gives invalid code #3560
Fantomas cannot parse the code it produced. The diagnostics are about that code.
A comment on its own line between a match clause's pattern and its when guard puts when on the column of the |, where it ends the clause, so the result does not parse. It does not matter whether the comment is on the | column or indented. Without the line break, | a // c followed by when a -> 1 on the next line, the result is valid, but the comment moves after when.
Regression in 8.0.8: 8.0.7 formats it validly (as | a when / // c / a / -> / 1). 8.0.8, 8.0.10, main and the 9.0.0-alpha-001 preview all fail. 8.0.8 is the release that fixed #3521 (comment after when on its own line is lost), by adding the range of the when keyword to the syntax tree, so that change looks related.
Found by formatting the vendored F# compiler's src/Compiler/SyntaxTree/LexFilter.fs, which has this shape (the CtxtFun offside rule).
Extra information
The formatted result breaks my code.
The formatted result gives compiler warnings.
I or my company would be willing to help fix this.
I would like a release if this problem is solved.
Options
Fantomas main branch at 2026-10-20T12:59:18Z - 79babfa
Default Fantomas configuration
Did you know that you can ignore files when formatting by using a .fantomasignore file? PS: It's unlikely that someone else will solve your specific issue, as it's something that you have a personal stake in.
Activity
Indent a when guard that has a comment before it