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 4 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 4 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

github-actions Bot commented May 20, 2026

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/11.0.100.md

T-Gro and others added 2 commits May 25, 2026 14:01
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