Skip to content

Conversation

@SergeyTeplyakov
Copy link
Owner

Introduces DoNotBlockUnnecessarilyInAsyncMethodsAnalyzer (EPC35) to detect and warn when Task.Result, Task.Wait(), or GetAwaiter().GetResult() are used inside async methods, which can cause deadlocks. Adds corresponding diagnostic descriptor, updates analyzer release notes, and provides comprehensive unit tests. Refactors TaskTypeExtensions for improved clarity and consistency.

Introduces DoNotBlockUnnecessarilyInAsyncMethodsAnalyzer (EPC35) to detect and warn when Task.Result, Task.Wait(), or GetAwaiter().GetResult() are used inside async methods, which can cause deadlocks. Adds corresponding diagnostic descriptor, updates analyzer release notes, and provides comprehensive unit tests. Refactors TaskTypeExtensions for improved clarity and consistency.
@SergeyTeplyakov SergeyTeplyakov requested a review from Copilot July 1, 2025 17:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new analyzer (EPC35) that warns when code blocks on tasks inside async methods, refactors a helper for clarity, and includes tests and release notes.

  • Introduces DoNotBlockUnnecessarilyInAsyncMethodsAnalyzer to detect Result, Wait(), and GetAwaiter().GetResult() inside async contexts
  • Updates TaskTypeExtensions parameter names for consistency
  • Adds diagnostic descriptor EPC35, release notes, and comprehensive unit tests

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/ErrorProne.NET.CoreAnalyzers/TaskTypeExtensions.cs Renamed method parameter from returnType to type for consistency
src/ErrorProne.NET.CoreAnalyzers/DiagnosticDescriptors.cs Added EPC35 descriptor for blocking in async methods
src/ErrorProne.NET.CoreAnalyzers/AsyncAnalyzers/DoNotBlockUnnecessarilyInAsyncMethodsAnalyzer.cs Implemented new analyzer logic for blocking APIs in async
src/ErrorProne.NET.CoreAnalyzers/AnalyzerReleases.Unshipped.md Documented EPC35 in release notes
src/ErrorProne.NET.CoreAnalyzers.Tests/AsyncAnalyzers/DoNotBlockUnnecessarilyInAsyncMethodsAnalyzerTests.cs Added tests for Task.Result, Task.Wait(), GetAwaiter().GetResult() in async
Comments suppressed due to low confidence (2)

src/ErrorProne.NET.CoreAnalyzers/TaskTypeExtensions.cs:36

  • [nitpick] Consider renaming the parameter type to something like typeSymbol to clarify that this represents a Roslyn symbol and avoid confusion with the C# type keyword.
    public static bool IsTaskLike(this ITypeSymbol? type, Compilation compilation, TaskLikeTypes typesToCheck)

src/ErrorProne.NET.CoreAnalyzers/AsyncAnalyzers/DoNotBlockUnnecessarilyInAsyncMethodsAnalyzer.cs:41

  • Add unit tests covering ValueTask<T>.Result usage inside async methods to verify that the analyzer correctly flags blocking on ValueTask results as well.
                propertyReference.Instance?.Type?.IsTaskLike(context.Compilation) == true)

@SergeyTeplyakov SergeyTeplyakov merged commit 5aad158 into master Jul 1, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants