Skip to content

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

Merged
T-Gro merged 7 commits into
mainfrom
copilot/fix-valid-type-alias-error
Jun 4, 2026
Merged

Fix parser error for anonymous record type aliases with postfix type operators when closing bracket is column-aligned#19762
T-Gro merged 7 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
@T-Gro T-Gro marked this pull request as ready for review May 28, 2026 14:29
@T-Gro T-Gro requested a review from a team as a code owner May 28, 2026 14:29
@T-Gro T-Gro enabled auto-merge (squash) May 28, 2026 14:29
@T-Gro T-Gro requested a review from abonie May 28, 2026 14:29
@github-actions github-actions Bot added the AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed label May 28, 2026
@github-project-automation github-project-automation Bot moved this from New to In Progress in F# Compiler and Tooling Jun 2, 2026
@T-Gro T-Gro merged commit bc8a51b into main Jun 4, 2026
50 checks passed
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 AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Valid type alias with anonymous record report error

3 participants