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
to be sure I get the requirements right.
A use in a local func should not trigger a warning, right? Only top level use expressions in the async/task returning function.
Right?
letfoo()=letlocalFunc()=use t =new DisposableThing()// warning here?()async{return"hi"}
That's correct, because I think most readers would correctly expect the use to be disposed when leaving the scope of the local function. The analyser is specifically to catch the unintended interaction between implicit-disposal (from use) and deferred execution (from Async/Task); I think there's much less likely to be a bug in code of the creation-and-disposal-within-local-function pattern you quoted there.
In principle we could catch a related bug, I guess, where we return anything that closes over the disposed object:
This isn't quite the same as the async bug (though it is very related), but I think it's probably much less common and it's also got many more edge cases to consider, so we should probably just ignore that one.
Original request by @Smaug123:
We should warn that
use blah
will be disposed of before the async is run. This should happen when a function returns anAsync/Task
.An additional request is that this check can be disabled by a code comment.
Something like:
The text was updated successfully, but these errors were encountered: