Skip to content

Do not classify recursive self-reference ref cells as mutable - #19918

Merged
T-Gro merged 4 commits into
mainfrom
fix/issue-5229
Jun 25, 2026
Merged

Do not classify recursive self-reference ref cells as mutable#19918
T-Gro merged 4 commits into
mainfrom
fix/issue-5229

Conversation

@T-Gro

@T-GroT-Gro commented Jun 9, 2026

Copy link
Copy Markdown
Member

Fixes#5229

SemanticClassification.isValRefMutable treated compiler-generated ref
cells for recursive self-references (as this, let rec self-refs) as
user-written mutable bindings, causing wrong IDE colorization.

Copilotand others added 3 commits June 9, 2026 08:29
…bleVar)
Adds positive and negative coverage for SemanticClassification of `as this` self-references in class bodies. These tests currently fail because isValRefMutable in SemanticClassification.fs treats the internal ref-cell compilation of CtorThisVal as a user-written mutable binding. Sprint 02 applies the surgical fix to make them pass.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The compiler compiles recursive object self-references (`as this`,
recursive `let rec` self-refs) through a ref cell for initialization.
SemanticClassification.isValRefMutable previously treated that internal
ref cell as a user-written mutable binding, causing the IDE colorizer
to paint the self-reference with the MutableVar shade.
Mirror the existing guard in FSharpMemberOrFunctionOrValue.IsMutable
(src/Compiler/Symbols/Symbols.fs) by excluding vref.IsCtorThisVal from
the isRefCellTy branch.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Apply dotnet fantomas to the SemanticClassification fix and its regression tests (both already conformant, no diff); add a release-notes entry for the service-side change. No production logic changes.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

❗ Release notes required

You can open this PR in browser to add release notes: open in github.dev


✅ Found changes and release notes in following paths:

Warning

No PR link found in some release notes, please consider adding it.

Change pathRelease notes pathDescription
src/Compilerdocs/release-notes/.FSharp.Compiler.Service/11.0.100.mdNo current pull request URL (#19918) found, please consider adding it

@github-actionsgithub-actionsBot added the AI-Tooling-Check-Bypassed Tooling check: non-fork PR, not diff-analyzed label Jun 9, 2026
@T-Gro
T-Gro requested a review from abonieJune 12, 2026 10:08

@T-GroT-Gro left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Clean fix. The one-line guard (not vref.IsCtorThisVal) mirrors the existing parallel logic in Symbols.fs line 2376 (IsRefCell), so both the public API and semantic classification now agree on what constitutes a mutable binding.

Tests cover the positive case (as this not marked mutable), theory variants, and negative guards (real mutable/ref-cell/byref/record-field bindings still classified correctly). Release notes entry is accurate.

LGTM — ship it.

@T-GroT-Gro added the AI-reviewed PR reviewed by AI review council label Jun 12, 2026
@T-Gro
T-Gro enabled auto-merge (squash) June 18, 2026 14:19
@github-project-automationgithub-project-automationBot moved this from New to In Progress in F# Compiler and ToolingJun 22, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-reviewedPR reviewed by AI review councilAI-Tooling-Check-BypassedTooling check: non-fork PR, not diff-analyzed

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Recursive object reference colored as a mutable variable

2 participants

@T-Gro@abonie