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 after 'when' on its own line is lost #3521
A line comment directly after when is lost when when starts its own line below the pattern. The output is valid F#, but the comment is gone.
It needs only the default settings. It does not happen when:
when is on the same line as the pattern (| _ when // c keeps the comment),
the comment is on its own line after when,
the comment is after the pattern and before when (| _ // c then when a -> b).
The same happens in function and in try ... with.
It is not a regression: 8.0.7, 7.0.6, 6.3.16 and 5.2.4 drop the comment too, and so does main.
The untyped tree gives when no range (SynMatchClauseTrivia has ArrowRange and BarRange only), so the Oak has no node on the comment's line to attach it to. The pattern ends on the line above and the guard starts on the line below. #1851 was the same problem for a comment after match.
The code comes from the F# compiler, src/Compiler/Checking/ConstraintSolver.fs (two when // Ignore any explicit ... overloads guards).
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-06T23:08:00Z - 6276e9e
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
Add range of the when keyword to SynMatchClauseTrivia (#20734)
Add changelog entries for the FCS update and fsprojects#3521
Keep a comment after a when keyword on its own line
Bump the packages group with 10 updates (#280)