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
Runtime async: a consumer on LangVersion 11.0 in Debug calls a library builder without FS3350 and gets a wrong result #21001
SDK 11.0.100, FSharp.Core 11.0.101, net11.0. Two projects: a library, and a console app that references it with ProjectReference.
Library (LangVersionpreview):
namespaceLibopenSystem.Threading.TasksopenSystem.Runtime.CompilerServicesopenMicrosoft.FSharp.Core.CompilerServicestypeB()=member inline_.Delay([<InlineIfLambda>]f:unit ->'T)= f
member inline_.Return(x)= x
member inline_.Bind(t:Task<'T>,[<InlineIfLambda>]k:'T ->'U)= k (AsyncHelpers.Await t)member inline_.Run([<InlineIfLambda>]code:unit ->'T):Task<'T>=__runtimeAsyncReturn (code ())[<AutoOpen>]moduleM =letb= B()
Consumer (default LangVersion, so F# 11.0), Debug:
openSystem.Threading.TasksopenLibletslow()=task{do! Task.Delay 50return20}typeW=static memberWork()=
b {let!x= slow ()let!y= Task.FromResult 22return x + y
}[<EntryPoint>]letmain _ =
printfn "result %d"(W.Work().Result)0
Expected
The consumer build fails with FS3350, as it does in Release:
error FS3350: Feature 'runtime async' is not available in F# 11.0. Please use language version 'PREVIEW' or greater.
Actual
In Debug, the build succeeds with no diagnostic. The consumer calls the compiled Lib.B::Run and Lib.B::Bind methods, so AsyncHelpers.Await runs outside a runtime-async method. The program prints result 1045044550 in place of result 42.
With [<NoDynamicInvocation>] on each builder member, the Debug build fails with FS3350 and FS3918, as expected.
Notes
The compiled non-inline copy of Bind calls AsyncHelpers.Await in a method that is not runtime async. Code generation does not reject it, because the docs treat explicitly inline bodies as templates.
With LangVersionpreview in the consumer, Debug and Release both give 42.
This issue was written with help from an AI coding agent (automated post). I reproduced it on SDK 11.0.100 while I added runtime-async builders to IcedTasks.
Activity