[Repo Assist] Fix FormatException when #if directive appears in mutually recursive type definition#3315
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
When an `and` type definition has compiler directives (`#if`/`#endif`) between its attribute lists, genOnelinerAttributes was silently dropping ContentBefore directives for all but the first AttributeListNode. This caused mergeMultipleFormatResults to see different hash-fragment counts across define variants and throw a FormatException. Also, the type name header was not being indented when emitting the attributes, which could produce invalid F# (parse error) in the non-DEBUG define path. Fix: in genOnelinerAttributes, detect when directives exist between attribute lists and render each AttributeListNode individually via genNode. In genTypeDefn, detect when an `and` definition has directive-bearing attributes and indent the header to ensure validity in all define variants. Closes #3174 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
31 tasks
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 PR was created by Repo Assist, an automated AI assistant.
Closes #3174
Supersedes #3290 (rebased on current
mainafter the lambda refactor in #3303)Root Cause
When an
andtype definition has compiler directives (#if/#endif) between its attribute lists, two separate bugs interact to cause aFormatException:genOnelinerAttributeswas flattening allAttributeListNodelists into a single combined[(Attr1)][(Attr2)]render, silently dropping theContentBeforetrivia (the#if/#endifdirectives) of all but the first list.mergeMultipleFormatResultsthen saw different hash-fragment counts across define variants and threw:genTypeDefndid not indent theandheader when attributes contain directives, which could produce invalid F# in some define paths (e.g.and\n[(Attr)] Y = intat column 0 is a parse error).Fix
genOnelinerAttributes: detect when any attribute list after the first has aTriviaContent.Directivein itsContentBefore. In that case, render eachAttributeListNodeindividually viagenNode(preserving directives) separated by newlines, rather than flattening into a single node. The common (no-directive) case is unchanged.genTypeDefn: addhasAttributeDirectivesForAndDefinitioncheck. When ananddefinition has directive trivia in its attribute lists, setshouldIndentAfterKeyword = trueto indent the header — the same treatment already applied when there are directives after the leading keyword identifier (hasTriviaAfterLeadingKeyword).Example
Before (throws
FormatException):After:
Trade-offs
genOnelinerAttributesandgenTypeDefnare modifiedanddefinitions without directives is unchangedTest Status
#if in mutually recursive type definition does not throw FormatException, 3174FormatException