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
Was porting an old project (netcoreapp2.2) to 3.1 today, noticed something that did compile back then that doesn't anymore.
This code is not sufficiently generic. The type variable ^TEntity when ^TEntity : not struct could not be generalized because it would escape its scope
Note the compiler inferred an SRTP type var ^TEntity here even though no SRTP constraints are used.
openFSharp.Control.Tasks.V2.ContextInsensitiveopenMicrosoft.EntityFrameworkCoretypeDbSet<'TEntitywhen'TEntity:notstruct>withmemberthis.TryFindAsync(keyValues)=task{let!r= this.FindAsync(keyValues)if obj.ReferenceEquals(r,null)thenreturn ValueNone
elsereturn ValueSome r
}
What seems to have happened here is EF moving from returning Task<'T> in 2.x to ValueTask<'T> in 3.x that caused this error to surface.
I've produced a minimal repro
openFSharp.Control.Tasks.V2.ContextInsensitivetypeFoo<'T>=memberthis.FindAsync()= ValueTask<_>(Unchecked.defaultof<'T>)memberthis.TryFindAsync()=task{let!r= this.FindAsync()if obj.ReferenceEquals(r,null)thenreturn ValueNone
elsereturn ValueSome r
}
My hunch is something is iffy around the SRTP based 'tasklike' Bind as ValueTask isn't directly supported.
Also, adding inline to the new member TryFindAsync to potentially flow the SRTP var doesn't work either and returns a different error:
The signature and implementation are not compatible because the type parameter in the class/signature has a different compile-time requirement to the one in the member/implementation
Finally to confirm my hunch I tried this code in Ply under netstandard2.0, where Ply has no explicit ValueTask overloads, only similar tasklike support, and under netcoreapp2.2 (which does have the overloads) both compile without errors. Something is going wrong with the SRTP constrained overloads in Taskbuilder.
Was porting an old project (netcoreapp2.2) to 3.1 today, noticed something that did compile back then that doesn't anymore.
Note the compiler inferred an SRTP type var
^TEntity
here even though no SRTP constraints are used.What seems to have happened here is EF moving from returning
Task<'T>
in 2.x toValueTask<'T>
in 3.x that caused this error to surface.I've produced a minimal repro
My hunch is something is iffy around the SRTP based 'tasklike'
Bind
as ValueTask isn't directly supported.Also, adding
inline
to the new memberTryFindAsync
to potentially flow the SRTP var doesn't work either and returns a different error:Finally to confirm my hunch I tried this code in Ply under
netstandard2.0
, where Ply has no explicitValueTask
overloads, only similar tasklike support, and undernetcoreapp2.2
(which does have the overloads) both compile without errors. Something is going wrong with the SRTP constrained overloads in Taskbuilder./cc: @gusty
The text was updated successfully, but these errors were encountered: