Skip to content

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

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-internal-error-disposable-cleanup
Draft

Fix ICE in BuildDisposableCleanup when Dispose extension methods are in scope#19568
Copilot wants to merge 2 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
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