Skip to content

Commit 8e82779

Browse files
CopilotT-Gro
andauthored
Fix ICE in BuildDisposableCleanup when Dispose extension methods are in scope (#19568)
* Initial plan * Fix ICE in BuildDisposableCleanup when Dispose extension methods are 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> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com> Co-authored-by: Tomas Grosup <Tomas.Grosup@gmail.com>
1 parent 8b756c1 commit 8e82779

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

docs/release-notes/.FSharp.Compiler.Service/11.0.100.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* Fix methods being tagged as `Member` instead of `Method` in tooltips. ([Issue #10540](https://github.com/dotnet/fsharp/issues/10540), [PR #19507](https://github.com/dotnet/fsharp/pull/19507))
4040
* Fix Debug-mode compilation when mixing resumable and standard computation expressions. ([Issue #19625](https://github.com/dotnet/fsharp/issues/19625), [PR #19630](https://github.com/dotnet/fsharp/pull/19630))
4141
* IlxGen: fix missing CompilationMapping attribute for generic values ([PR #19643](https://github.com/dotnet/fsharp/pull/19643))
42+
* Fix internal compiler error in `use` bindings when a C#-style `Dispose` extension method is in scope alongside `IDisposable.Dispose`. ([Issue #19552](https://github.com/dotnet/fsharp/issues/19552), [PR #19568](https://github.com/dotnet/fsharp/pull/19568))
4243
* Fix signature generation: single-case struct DU gets spurious bar causing FS0300. ([Issue #19597](https://github.com/dotnet/fsharp/issues/19597), [PR #19609](https://github.com/dotnet/fsharp/pull/19609))
4344
* Fix signature generation: backticked active pattern case names lose escaping. ([Issue #19592](https://github.com/dotnet/fsharp/issues/19592), [PR #19609](https://github.com/dotnet/fsharp/pull/19609))
4445
* Fix signature generation: `namespace global` header dropped from generated signature. ([Issue #19593](https://github.com/dotnet/fsharp/issues/19593), [PR #19609](https://github.com/dotnet/fsharp/pull/19609))

src/Compiler/Checking/Expressions/CheckExpressions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3155,7 +3155,7 @@ let BuildDisposableCleanup (cenv: cenv) env m (v: Val) =
31553155
v.SetHasBeenReferenced()
31563156

31573157
let disposeMethod =
3158-
match TryFindIntrinsicOrExtensionMethInfo ResultCollectionSettings.AllResults cenv env m ad "Dispose" g.system_IDisposable_ty with
3158+
match TryFindIntrinsicOrExtensionMethInfo ResultCollectionSettings.AtMostOneResult cenv env m ad "Dispose" g.system_IDisposable_ty with
31593159
| [x] -> x
31603160
| _ -> error(InternalError(FSComp.SR.tcCouldNotFindIDisposable(), m))
31613161

tests/FSharp.Compiler.ComponentTests/Conformance/BasicGrammarElements/UseBindings/UseBindings.fs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,29 @@ module UseBindings =
4545
|> asFsx
4646
|> compile
4747
|> shouldSucceed
48+
49+
[<Fact>]
50+
let ``use binding does not ICE when Dispose extension method is in scope`` () =
51+
FSharp """
52+
open System
53+
open System.Runtime.CompilerServices
54+
55+
type Disposable() =
56+
interface IDisposable with
57+
member _.Dispose() = ()
58+
59+
[<Extension>]
60+
type PublicExtensions =
61+
[<Extension>]
62+
static member inline Dispose(this: #IDisposable) =
63+
this
64+
65+
let foo() =
66+
use a = new Disposable()
67+
()
68+
69+
foo()
70+
"""
71+
|> asExe
72+
|> compile
73+
|> shouldSucceed

0 commit comments

Comments
 (0)