Fix parser error for anonymous record type aliases with postfix type operators when closing bracket is column-aligned#19762
Fix parser error for anonymous record type aliases with postfix type operators when closing bracket is column-aligned#19762Copilot wants to merge 2 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>
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.
❗ Release notes requiredCaution No release notes found for the changed paths (see table below). Please make sure to add an entry with an informative description of the change as well as link to this pull request, issue and language suggestion if applicable. Release notes for this repository are based on Keep A Changelog format. The following format is recommended for this repository:
If you believe that release notes are not necessary for this PR, please add NO_RELEASE_NOTES label to the pull request. You can open this PR in browser to add release notes: open in github.dev
|
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.