Update DetectPreviewFeatureAnalyzer for runtime async#50937
Update DetectPreviewFeatureAnalyzer for runtime async#50937333fred merged 3 commits intodotnet:release/10.0.1xxfrom
Conversation
We need to be giving warnings around enabling preview features for runtime async. This updates the analyzer to do this.
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Pull Request Overview
This PR updates the DetectPreviewFeatureAnalyzer to support runtime async features by adding support for detecting when await operations use preview features. The changes specifically add handling for IAwaitOperation in the analyzer and create infrastructure to check if await expressions use runtime-specific methods that require preview feature opt-in.
- Adds await operation handling to the core analyzer framework
- Implements C# and VB.NET specific symbol extraction for await operations
- Creates lightup wrapper for accessing RuntimeAwaitMethod property
- Adds comprehensive unit tests for runtime async preview feature detection
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| DetectPreviewFeatureUnitTests.Misc.cs | Adds unit tests for verifying runtime async preview feature diagnostics |
| LightupHelpers.cs | Changes CreatePropertyAccessor method visibility from private to internal |
| AwaitExpressionInfoWrapper.cs | New lightup wrapper for accessing RuntimeAwaitMethod property from AwaitExpressionInfo |
| Analyzer.CSharp.Utilities.projitems | Includes the new AwaitExpressionInfoWrapper in the build |
| BasicDetectPreviewFeatureAnalyzer.vb | Implements VB.NET-specific SymbolFromAwaitOperation method (returns null) |
| DetectPreviewFeatureAnalyzer.cs | Adds await operation support to the core analyzer with abstract method for language-specific handling |
| CSharpDetectPreviewFeatureAnalyzer.cs | Implements C#-specific await operation symbol extraction using RuntimeAwaitMethod |
...odeAnalysis.NetAnalyzers/src/Utilities/Compiler.CSharp/Lightup/AwaitExpressionInfoWrapper.cs
Show resolved
Hide resolved
...odeAnalysis.NetAnalyzers/src/Utilities/Compiler.CSharp/Lightup/AwaitExpressionInfoWrapper.cs
Show resolved
Hide resolved
| using Microsoft.CodeAnalysis.Diagnostics; | ||
| using Microsoft.CodeAnalysis.Operations; | ||
| using Microsoft.NetCore.Analyzers.Runtime; | ||
| using Analyzer.Utilities.Lightup; |
| { | ||
| protected override ISymbol? SymbolFromAwaitOperation(IAwaitOperation operation) | ||
| { | ||
| if (operation.Syntax is not AwaitExpressionSyntax awaitSyntax) |
There was a problem hiding this comment.
Consider testing with await using and await foreach
There was a problem hiding this comment.
These are going to need new public APIs. I'll open a followup.
| fallbackResult: null); | ||
| }); | ||
|
|
||
| return s_RuntimeAwaitMethodAccessor!(info); |
| { | ||
| async Task M() | ||
| { | ||
| await Task.Yield(); |
There was a problem hiding this comment.
I didn't follow, what's the "custom awaiter" part here. From the name of the test, I expected to see a definition with a custom type with a custom awaiter. Never mind, it's using UnsafeAwaitAwaiter #Closed
jcouv
left a comment
There was a problem hiding this comment.
Done with review pass (commit 1)
|
@jcouv please take another look. |
Failures
FullFramework: Windows x64I have no idea. My teammates said we could update the version used for the test, but I don't know why it is failing in this PR. Also, @dsplaisted said:
TemplateEngine Windows x64Also have no idea. It got a completely different set of table outputs with missing entries. Also, the Type and Language columns are not populated.
TestBuild Linux x64This is a know test failure. We just rerun this one until it passes. Thread about it here: #50784 |



We need to be giving warnings around enabling preview features for runtime async. This updates the analyzer to do this.
Relates to test plan dotnet/roslyn#75960