Skip to content

Fix parser error for anonymous record type aliases with postfix type operators when closing bracket is column-aligned#19762

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-valid-type-alias-error
Draft

Fix parser error for anonymous record type aliases with postfix type operators when closing bracket is column-aligned#19762
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-valid-type-alias-error

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 18, 2026

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:

type T =
    {| Id: Guid
    |} []     // error FS0010: Unexpected symbol '[' in member definition
    
type U =
    {| Id: Guid
    |} seq    // error FS0010: Unexpected identifier in member definition

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 synthetic ODUMMY BAR_RBRACE token is queued at that same position. The offside rule for type sequence blocks checks isTypeSeqBlockElementContinuator to decide whether to insert OBLOCKSEP. Since BAR_RBRACE was absent from that function, the dummy token at the same column as the outer CtxtSeqBlock triggered OBLOCKSEP insertion, causing the parser to enter class-member context — where [ and seq are invalid.

BAR_RBRACE was already present in isSeqBlockElementContinuator (expression contexts); the type context was simply missing the same treatment.

Changes

  • src/Compiler/SyntaxTree/LexFilter.fs — add BAR_RBRACE to isTypeSeqBlockElementContinuator, preventing spurious OBLOCKSEP insertion after |} in type definition contexts.
  • tests/FSharp.Compiler.ComponentTests/Conformance/Types/RecordTypes/AnonymousRecords.fs — add TypeAliasIndentation module with tests covering [], seq, list, option postfixes with column-aligned brackets, multi-field records, and the already-working single-line form.

…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
Copilot AI requested a review from T-Gro May 18, 2026 12:31
Copilot finished work on behalf of T-Gro May 18, 2026 12:31
Copy link
Copy Markdown
Member

@T-Gro T-Gro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@T-Gro T-Gro self-requested a review May 20, 2026 12:51
@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label May 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

❗ Release notes required

@copilot,

Caution

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:

* <Informative description>. ([PR #XXXXX](https://github.com/dotnet/fsharp/pull/XXXXX))

See examples in the files, listed in the table below or in th full documentation at https://fsharp.github.io/fsharp-compiler-docs/release-notes/About.html.

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

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/11.0.100.md No release notes found or release notes format is not correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-reviewed PR reviewed by AI review council

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

Valid type alias with anonymous record report error

2 participants