Fixes handling of methods Task.WaitAsync and SemaphoreSlim.WaitAsync#122
Open
michelebastione wants to merge 3 commits into
Open
Fixes handling of methods Task.WaitAsync and SemaphoreSlim.WaitAsync#122michelebastione wants to merge 3 commits into
michelebastione wants to merge 3 commits into
Conversation
…ed instead of just renaming the original method.
…d subsequently being dropped during rewriting
This file contains hidden or 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
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
This PR addresses two closely related bugs that caused entire method bodies being inadvertently dropped at the invocation of
Task.WaitAsyncorSemaphoreSlim.WaitAsync.Both issues originated from a syntax check for the string "WaitAsync":
AsyncToSyncRewriter.ReplaceAsyncthe pattern matching for case MemberAccessExpressionSyntax lacked a fallback for validation purposes (when called fromEndWithAsync). Hence WaitAsync calls chained at the end of a method (e.g.,FooAsync().WaitAsync()) made the entire expression chain always return null, leading to them ultimately being discarded.ExpressionSyntaxvalue, there was no differentiation between Task methods, which are supposed to be dropped, and methods such asSemaphoreSlim.WaitAsync, which should be converted toSemaphoreSlim.Waitinstead. As a result, synchronization primitives were being deleted from the generated code.Changes Introduced
ReplaceAsyncandEndsWithAsync. The latter now implements a fallback to a non null value for the MemberAccessExpressionSyntax pattern matching case, thus preventing the entire chain call to be dropped.TryReplaceIdentifiermethod that uses the code block'sSemanticModelfor making sure that a symbol called "WaitAsync" is removed only when its containing type corresponds toSystem.Threading.Tasks.TaskorSystem.Threading.Tasks.TimeProviderTaskExtensions.fixes #119
fixes #121