Fix parser error for anonymous record type aliases with postfix type operators when closing bracket is column-aligned#19762
Draft
Copilot wants to merge 4 commits into
Draft
Fix parser error for anonymous record type aliases with postfix type operators when closing bracket is column-aligned#19762Copilot wants to merge 4 commits into
Copilot wants to merge 4 commits into
Conversation
…when closing bracket is aligned with opening bracket
Add BAR_RBRACE to isTypeSeqBlockElementContinuator in LexFilter.fs to prevent incorrect OBLOCKSEP insertion after closing |} in type alias contexts. This fixes the error 'Unexpected symbol [' in member definition' when writing:
type T =
{| Id: Guid
|} [] // or |} seq, |} list, |} option
Add tests covering the fixed cases in AnonymousRecords.fs.
Agent-Logs-Url: https://github.com/dotnet/fsharp/sessions/efa54b78-f657-43e6-a50e-05db045cba9d
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix valid type alias with anonymous record compiler error
Fix parser error for anonymous record type aliases with postfix type operators when closing bracket is column-aligned
May 18, 2026
T-Gro
approved these changes
May 20, 2026
Member
T-Gro
left a comment
There was a problem hiding this comment.
Clean, well-targeted fix. The root cause analysis is correct: BAR_RBRACE was already handled in isSeqBlockElementContinuator (expression contexts) but was missing from isTypeSeqBlockElementContinuator (type definition contexts), causing spurious OBLOCKSEP insertion when |} is column-aligned.
The one-line change is minimal and mirrors the existing pattern for BAR in the same function. Tests cover the key variants (array, seq, list, option postfixes), multi-field records, and the already-working single-line form as a regression guard.
LGTM.
Contributor
❗ Release notes required
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
When the closing
|}of an anonymous record type alias is vertically aligned with the opening{|, any postfix type operator on the same line causes a spurious parse error:Workarounds were to either indent
|}one extra space or use prefix generic syntax (array<{| Id: Guid |}>, etc.).Root Cause
In
LexFilter.fs, after|}(BAR_RBRACE) closes an anonymous record type, a syntheticODUMMY BAR_RBRACEtoken is queued at that same position. The offside rule for type sequence blocks checksisTypeSeqBlockElementContinuatorto decide whether to insertOBLOCKSEP. SinceBAR_RBRACEwas absent from that function, the dummy token at the same column as the outerCtxtSeqBlocktriggeredOBLOCKSEPinsertion, causing the parser to enter class-member context — where[andseqare invalid.BAR_RBRACEwas already present inisSeqBlockElementContinuator(expression contexts); the type context was simply missing the same treatment.Changes
src/Compiler/SyntaxTree/LexFilter.fs— addBAR_RBRACEtoisTypeSeqBlockElementContinuator, preventing spuriousOBLOCKSEPinsertion after|}in type definition contexts.tests/FSharp.Compiler.ComponentTests/Conformance/Types/RecordTypes/AnonymousRecords.fs— addTypeAliasIndentationmodule with tests covering[],seq,list,optionpostfixes with column-aligned brackets, multi-field records, and the already-working single-line form.