-
-
Notifications
You must be signed in to change notification settings - Fork 258
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
Support duck-typed awaitables and task-like types for Task/Async-related analyzers #1535
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Also add corresponding tests
Add tests for RCS1229 covering duck-typed awaitables Fix some RCS1229 tests being grouped under RCS1228
Custom task type can compile to a full state machine without being awaitable Add more to RCS1229 tests Add tests to RCS1261 since it uses the same fixer code as RCS1229
Better match the real check performed by the compiler (check member visibility, check for implementing INotifyCompletion instead of just the OnCompleted method)
@dotnet-policy-service agree |
@Govorunb build failed |
josefpihrt
requested changes
Sep 28, 2024
src/Analyzers.CodeFixes/CSharp/SyntaxRewriters/UseAsyncAwaitRewriter.cs
Outdated
Show resolved
Hide resolved
@Govorunb Please update changelog. |
Types derived from Task(<T>) aren't special-cased and thus aren't inherently task-like Likewise with awaitability, a derived type could declare a `new GetAwaiter` method (like Task<T> does) that actually doesn't return a valid awaiter type, so inheritance cannot be used to prove a type is awaitable
josefpihrt
requested changes
Sep 28, 2024
Add null checks Inline "task-like" check
josefpihrt
reviewed
Sep 30, 2024
josefpihrt
approved these changes
Sep 30, 2024
@Govorunb Great PR! Thanks for the contribution. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
These changes add the same logic for checking duck-typed awaitables and task-like types that is currently in Roslyn.
This resolves #1529 - specifically, these analyzers/refactorings become aware of custom awaitables/custom task-like types:
Async
)ConfigureAwait(false)
)async
/await
)async
/await
)Remarks
RCS1090's behaviour is less obvious here - it seems there is no official stance for duck-typing
ConfigureAwait
(even Roslyn isn't perfectly consistent), but I'm of the opinion that if the rest of the ducks are quacking, it's better to join the flock 😄 The result is that these checks are relaxed from theTask
-specificConfiguredTaskAwaitable(`1)
return type to any awaitable return type.I noticed there were some checks for WinRT async interfaces, these are covered as there's an extension
GetAwaiter()
method available on those types.I'm not experienced with analyzers and their edge cases so it's possible I've missed writing some obvious tests, I'd love to get your feedback.