Skip to content

[Repo Assist] Fix block comment after 'of' in union cases and exceptions#3286

Closed
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/fix-issue-1959-block-comment-after-of-58f78a136d945556
Closed

[Repo Assist] Fix block comment after 'of' in union cases and exceptions#3286
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/fix-issue-1959-block-comment-after-of-58f78a136d945556

Conversation

@github-actions
Copy link
Contributor

🤖 This is an automated PR from Repo Assist.

Closes #1959

Problem

Block comments positioned between of and the first field type in union cases and exception types were incorrectly moved before of in the formatted output.

Input:

exception LoadedSourceNotFoundIgnoring of (*filename*) string * range
type T = | Foo of (*label*) int * string

Before (buggy):

exception LoadedSourceNotFoundIgnoring (*filename*) of string * range
type T = Foo of (*label*) int * string  // comment was lost to before 'of'

After (fixed):

exception LoadedSourceNotFoundIgnoring of (*filename*) string * range
type T = Foo of (*label*) int * string

Root Cause

In blockCommentToTriviaInstruction (Trivia.fs), when the comment sits on the same line as nodeBefore (the union case identifier), the logic unconditionally called nb.AddAfter — attaching the comment after the identifier. However, the of keyword is implicit (not a separate AST node), so this placed the comment before of in the output.

Fix

Added a special case: when the container is a UnionCaseNode and nodeBefore is the identifier (SingleTextNode), use na.AddBefore (attach before the first FieldNode) instead of nb.AddAfter. This correctly places the comment after the implicit of.

The fix is guarded so it only applies to this specific scenario — comments between fields (where nodeBefore is an IdentListNode, not a SingleTextNode) are unaffected.

Tests

  • Added block comment between 'of' and field type in exception stays after 'of', 1959
  • Added block comment between 'of' and field type in union case stays after 'of', 1959
  • Updated block comments in type definition, 1975 — this test was documenting the old buggy behaviour; corrected expected output
  • All 2739 tests pass, 7 skipped

Test Status

✅ Build succeeded
✅ All 2739 tests pass (0 failures, 7 skipped)

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

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>
@nojaf
Copy link
Contributor

nojaf commented Mar 16, 2026

/repo-assist the real fix here is having the off keyword as trivia on the parser side.

@nojaf nojaf closed this Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong change of comment's position

1 participant