You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unexpected type inference for Run method - generic constraints are checked too late #19349
openSystem.Runtime.CompilerServices// -------------------------// "View engine" bits// -------------------------typeHtmlContainer()=classendtypeHtmlContainerFun= HtmlContainer -> unit
[<Extension>]typeHtmlContainerExtensions=[<Extension>]static member inlineRun(this:#HtmlContainer,[<InlineIfLambda>]runExpr:HtmlContainerFun)=
runExpr this
this
// -------------------------// "AsyncSeq-like" CE builder bits// -------------------------typeAsyncSeq<'T>=private AsyncSeq of'TlisttypeAsyncSeqBuilder()=member_.Yield(x:'T):AsyncSeq<'T>=
AsyncSeq [x]letasyncSeq= AsyncSeqBuilder()letxs:AsyncSeq<int>=
asyncSeq {yield1}
From Don's comment:
This could be onsidered an F# compiler bug but we'd have to check the spec - the compiler commits to using this Run before it knows the constraint check #HtmlContainer will fail.
Expected behavior
Code compiles just fine - Run method from HtmlContainerExtensions isn't used for asyncSeq
Actual behavior
error FS0193: The type 'AsyncSeqBuilder' is not compatible with the type 'HtmlContainer'
I'm sustecting an invalid way of finding methods. For instance, in your case, the compiler tries to find a method with name "Run" in list of unindexed extensions methods (likewise this generic method). Therefore, the method is used for AsyncSeqBuilder as that method exists.
To clarify, another example:
openSystem.Runtime.CompilerServicesopenSystem// -------------------------// "View engine" bits// -------------------------typeHtmlContainer()=classendtypeHtmlContainerFun= HtmlContainer -> unit
[<Extension>]typeHtmlContainerExtensions=[<Extension>]static member inlineDispose(this:#HtmlContainer,[<InlineIfLambda>]runExpr:HtmlContainerFun)=
runExpr this
this
// -------------------------// "AsyncSeq-like" CE builder bits// -------------------------typeAsyncSeq<'T>=private AsyncSeq of'Tlistinterface IDisposable withmember_.Dispose()=()letfoo()=use a = AsyncSeq([1])1
This code also doesn't compile (error FS0073: internal error: Couldn't find Dispose on IDisposable, or it was overloaded), because "Dispose" extension method is taken into account.
I'm sustecting an invalid way of finding methods. For instance, in your case, the compiler tries to find a method with name "Run" in list of unindexed extensions methods (likewise this generic method). Therefore, the method is used for AsyncSeqBuilder as that method exists.
I'm not sure I understand the reason. I don't see any problem that compiler tries to find a method with name "Run" and finds it. In fact I want it to be found for the types that match generic restriction. The problem is that it decides to choose it even when types don't match.
Here's a code that tries to find a method called "Run" in a group that includes generic extension methods. Since there is no further checking, that type match generic restriction, a generic method is included into range of available methods. Identically, when the compiler gets method to find "Dispose", it's also getting generic method, dispite they aren't match generic restriction.
Here's a function that gets extension methods. As you can see, there is a param nenv.eUnindexedExtensionMembers. So, it finds methods among unindexed extension members that include generic extension methods.
letExtensionMethInfosOfTypeInScope(collectionSettings:ResultCollectionSettings)(infoReader:InfoReader)(nenv:NameResolutionEnv)optFilter isInstanceFilter m ty =
letextMemsDangling= SelectMethInfosFromExtMembers infoReader optFilter ty m nenv.eUnindexedExtensionMembers
if collectionSettings = ResultCollectionSettings.AtMostOneResult &¬(isNil extMemsDangling)then
Activity
evgTSV commentedon Feb 24, 2026
I'm sustecting an invalid way of finding methods. For instance, in your case, the compiler tries to find a method with name "Run" in list of unindexed extensions methods (likewise this generic method). Therefore, the method is used for AsyncSeqBuilder as that method exists.
To clarify, another example:
This code also doesn't compile (error FS0073: internal error: Couldn't find Dispose on IDisposable, or it was overloaded), because "Dispose" extension method is taken into account.
Lanayx commentedon Feb 25, 2026
I'm not sure I understand the reason. I don't see any problem that compiler tries to find a method with name "Run" and finds it. In fact I want it to be found for the types that match generic restriction. The problem is that it decides to choose it even when types don't match.
evgTSV commentedon Feb 25, 2026
Here's a code that tries to find a method called "Run" in a group that includes generic extension methods. Since there is no further checking, that type match generic restriction, a generic method is included into range of available methods. Identically, when the compiler gets method to find "Dispose", it's also getting generic method, dispite they aren't match generic restriction.
fsharp/src/Compiler/Checking/Expressions/CheckComputationExpressions.fs
Lines 3083 to 3086 in 7d0437e
Here's a function that gets extension methods. As you can see, there is a param nenv.eUnindexedExtensionMembers. So, it finds methods among unindexed extension members that include generic extension methods.
fsharp/src/Compiler/Checking/NameResolution.fs
Lines 723 to 726 in 7d0437e
Fix FS1110 in task { let! } when generic IL extension is in scope (#1…
Fix FS1110 in task { let! } when generic IL extension is in scope (#1…