Skip to content

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

Open
Copilot wants to merge 3 commits intomainfrom
copilot/fix-internal-error-disposable-cleanup
Open

Fix ICE in BuildDisposableCleanup when Dispose extension methods are in scope#19568
Copilot wants to merge 3 commits intomainfrom
copilot/fix-internal-error-disposable-cleanup

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

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.

open System
open System.Runtime.CompilerServices

type Disposable() =
    interface IDisposable with 
        member _.Dispose() = ()

[<Extension>]
type PublicExtensions =
    [<Extension>]
    static member inline Dispose(this: #IDisposable) = this

let foo() =
    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.

…in scope

Use AtMostOneResult to leverage existing intrinsic-over-extension priority in
AllMethInfosOfTypeInScope, matching how regular method calls resolve Dispose.

Agent-Logs-Url: https://github.com/dotnet/fsharp/sessions/ebba43f1-81b6-417c-9138-f5867056fd94

Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix internal error in BuildDisposableCleanup with multiple Dispose candidates Fix ICE in BuildDisposableCleanup when Dispose extension methods are in scope Apr 10, 2026
Copilot AI requested a review from T-Gro April 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 owner April 20, 2026 20:36
@T-Gro T-Gro requested a review from abonie April 20, 2026 20:37
@T-Gro T-Gro enabled auto-merge (squash) April 20, 2026 20:37
@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

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

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

2 participants