[Repo Assist] Fix block comment after 'of' in union cases and exceptions#3286
Closed
github-actions[bot] wants to merge 1 commit intomainfrom
Closed
Conversation
Block comments positioned between 'of' and the first field type in union cases (and exception types) were incorrectly placed before 'of' in the formatted output. Root cause: blockCommentToTriviaInstruction would call nb.AddAfter (attaching the comment after the union case identifier), but since the 'of' keyword is implicit (not a separate AST node), this placed the comment before 'of' in the output. Fix: when the container is a UnionCaseNode and nodeBefore is the identifier (a SingleTextNode), prefer na.AddBefore (attaching the comment before the first FieldNode) instead of nb.AddAfter. This correctly places the comment after the implicit 'of'. Closes #1959 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
28 tasks
Contributor
|
/repo-assist the real fix here is having the off keyword as trivia on the parser side. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated PR from Repo Assist.
Closes #1959
Problem
Block comments positioned between
ofand the first field type in union cases and exception types were incorrectly moved beforeofin the formatted output.Input:
Before (buggy):
After (fixed):
Root Cause
In
blockCommentToTriviaInstruction(Trivia.fs), when the comment sits on the same line asnodeBefore(the union case identifier), the logic unconditionally callednb.AddAfter— attaching the comment after the identifier. However, theofkeyword is implicit (not a separate AST node), so this placed the comment beforeofin the output.Fix
Added a special case: when the container is a
UnionCaseNodeandnodeBeforeis the identifier (SingleTextNode), usena.AddBefore(attach before the firstFieldNode) instead ofnb.AddAfter. This correctly places the comment after the implicitof.The fix is guarded so it only applies to this specific scenario — comments between fields (where
nodeBeforeis anIdentListNode, not aSingleTextNode) are unaffected.Tests
block comment between 'of' and field type in exception stays after 'of', 1959block comment between 'of' and field type in union case stays after 'of', 1959block comments in type definition, 1975— this test was documenting the old buggy behaviour; corrected expected outputTest Status
✅ Build succeeded
✅ All 2739 tests pass (0 failures, 7 skipped)