Skip to content

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

Merged
T-Gro merged 3 commits intomainfrom
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 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.

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

github-actions Bot commented Apr 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 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-Gro force-pushed the copilot/fix-internal-error-disposable-cleanup branch from 96a6103 to c44e99a Compare April 21, 2026 07:59
@github-project-automation github-project-automation Bot moved this from New to In Progress in F# Compiler and Tooling Apr 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-Gro force-pushed the copilot/fix-internal-error-disposable-cleanup branch from c44e99a to f01848a Compare April 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-Gro force-pushed the copilot/fix-internal-error-disposable-cleanup branch from f01848a to cd7f35f Compare April 28, 2026 09:13
@T-Gro T-Gro merged commit 8e82779 into main May 4, 2026
50 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in F# Compiler and Tooling May 4, 2026
Sign up for free to 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