Skip to content

Fix ICE in BuildDisposableCleanup when Dispose extension methods are in scope - #19568

Merged
T-Gro merged 3 commits into
mainfrom
copilot/fix-internal-error-disposable-cleanup
May 4, 2026
Merged

Fix ICE in BuildDisposableCleanup when Dispose extension methods are in scope#19568
T-Gro merged 3 commits into
mainfrom
copilot/fix-internal-error-disposable-cleanup

Conversation

CopilotAI commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

BuildDisposableCleanup crashes with an ICE ("Couldn't find Dispose on IDisposable, or it was overloaded") when a C#-style Dispose extension method is in scope alongside the intrinsic IDisposable.Dispose.

openSystemopenSystem.Runtime.CompilerServicestypeDisposable()=interface IDisposable withmember_.Dispose()=()[<Extension>]typePublicExtensions=[<Extension>]static member inlineDispose(this:#IDisposable)= this
letfoo()=use a =new Disposable()// ICE here()

Cause

The lookup uses TryFindIntrinsicOrExtensionMethInfo with ResultCollectionSettings.AllResults, which collects both intrinsic and extension methods. The subsequent | [x] -> x match fails when >1 candidate is returned.

Fix

Switch to ResultCollectionSettings.AtMostOneResult. This leverages the existing priority mechanism in AllMethInfosOfTypeInScope — when intrinsic methods are found, extension methods are skipped. Same priority rules as a hand-written (x :> IDisposable).Dispose() call.

CopilotAI changed the title [WIP] Fix internal error in BuildDisposableCleanup with multiple Dispose candidatesFix ICE in BuildDisposableCleanup when Dispose extension methods are in scopeApr 10, 2026
CopilotAI requested a review from T-GroApril 10, 2026 10:27
@T-Gro
T-Gro marked this pull request as ready for review April 20, 2026 20:36
@T-Gro
T-Gro requested a review from a team as a code ownerApril 20, 2026 20:36
@T-Gro
T-Gro requested a review from abonieApril 20, 2026 20:37
@T-Gro
T-Gro enabled auto-merge (squash) April 20, 2026 20:37
@github-actions

github-actionsBot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

❗ Release notes required


✅ Found changes and release notes in following paths:

Change pathRelease notes pathDescription
src/Compilerdocs/release-notes/.FSharp.Compiler.Service/11.0.100.md

T-Gro added a commit that referenced this pull request Apr 21, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
T-Gro added a commit that referenced this pull request Apr 21, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@T-Gro
T-Groforce-pushed the copilot/fix-internal-error-disposable-cleanup branch from 96a6103 to c44e99aCompareApril 21, 2026 07:59
@github-project-automationgithub-project-automationBot moved this from New to In Progress in F# Compiler and ToolingApr 21, 2026
T-Gro added a commit that referenced this pull request Apr 28, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@T-Gro
T-Groforce-pushed the copilot/fix-internal-error-disposable-cleanup branch from c44e99a to f01848aCompareApril 28, 2026 09:05
…in scope
BuildDisposableCleanup crashes with an ICE when a C#-style Dispose extension method
is in scope alongside intrinsic IDisposable.Dispose. Switch from AllResults to
AtMostOneResult so intrinsic methods take priority, matching normal resolution rules.
Fixes#19552
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@T-Gro
T-Groforce-pushed the copilot/fix-internal-error-disposable-cleanup branch from f01848a to cd7f35fCompareApril 28, 2026 09:13
@T-Gro
T-Gro merged commit 8e82779 into mainMay 4, 2026
50 checks passed
@github-project-automationgithub-project-automationBot moved this from In Progress to Done in F# Compiler and ToolingMay 4, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[ICE] Internal error in BuildDisposableCleanup when multiple Dispose candidates are found

3 participants

@abonie@T-Gro