New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VSTHRD114: fires even in the function is annotated as returning nullable Tasks #637
Comments
We don't reference c# 8 compiler assemblies yet, so what you're asking would be difficult without dropping support for older toolsets. Do you think there's a legit case for ever returning null instead of a task? |
Absolutely. There were others in the Roslyn codebase as well, for example this one: This case was a TryStartProcess() where the failure to start the task was an error return that had to be handled differently. Returning a completed task wouldn't have been correct because the caller wouldn't know what happened. The Try* pattern specifically I don't see a good alternative for.
Analyzers usually just use reflection in this case; since you just have to read a property on the interface in this case. But yes, that's not fun either way. |
Just hit this again porting a different library to use vs-threading |
At this point, depending on Roslyn assemblies that are new enough to include the nullable ref annotations should be tolerable. |
…ble tasks. The implementation uses syntax nodes to detect the nullable return type. Converted VSTHRD114 to an abstract base class in order to use LanguageUtils.
Bug description
Consider this code:
https://github.com/dotnet/roslyn/blob/5f5c283ce3fbcdceb998d48aca4ed3c9792605e3/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Utilities/ValuesSources/WeaklyCachedRecoverableValueSource.cs#L141-L165
The "return null" at the end triggers the warning, which is a useful warning if this code wasn't null annotated. In this case however the function is marked as returning
Task?
and the compiler will warn if somebody tries to await it without checking for null first.Expected behavior
If the function is explicitly
Task?
returning, we don't analyze the method since the developer has explicitly indicated they know this, and the compiler will help check. If you're not on C# 8 or the code hasn't been annotated, then absolutely keep warning like it does today.Actual behavior
We're analyzing code unnecessarily.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: