Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

333fred
Copy link
Member

@333fred 333fred commented Sep 19, 2025

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

We need to be giving warnings around enabling preview features for runtime async. This updates the analyzer to do this.
@333fred 333fred requested a review from a team as a code owner September 19, 2025 18:05
@Copilot Copilot AI review requested due to automatic review settings September 19, 2025 18:05

This comment was marked as resolved.

@333fred 333fred changed the base branch from main to release/10.0.1xx September 19, 2025 18:06
@333fred 333fred changed the title analyzer warning Update DetectPreviewFeatureAnalyzer for runtime async Sep 19, 2025
Copy link
Contributor

@Copilot 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 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

Copy link
Member

@agocke agocke left a comment

Choose a reason for hiding this comment

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

LGTM

using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Operations;
using Microsoft.NetCore.Analyzers.Runtime;
using Analyzer.Utilities.Lightup;
Copy link
Member

Choose a reason for hiding this comment

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

sort usings?

{
protected override ISymbol? SymbolFromAwaitOperation(IAwaitOperation operation)
{
if (operation.Syntax is not AwaitExpressionSyntax awaitSyntax)
Copy link
Member

Choose a reason for hiding this comment

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

Consider testing with await using and await foreach

Copy link
Member Author

Choose a reason for hiding this comment

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

These are going to need new public APIs. I'll open a followup.

Copy link
Member Author

Choose a reason for hiding this comment

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

fallbackResult: null);
});

return s_RuntimeAwaitMethodAccessor!(info);
Copy link
Member

Choose a reason for hiding this comment

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

!

If we're following the same nullability guidelines as roslyn, we should favor an assertion over a suppression here

{
async Task M()
{
await Task.Yield();
Copy link
Member

@jcouv jcouv Sep 21, 2025

Choose a reason for hiding this comment

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

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

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

Done with review pass (commit 1)

@333fred
Copy link
Member Author

333fred commented Sep 22, 2025

@jcouv please take another look.

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (commit 2)

@333fred 333fred enabled auto-merge (squash) September 22, 2025 22:15
@MiYanni
Copy link
Member

MiYanni commented Sep 23, 2025

@333fred

Failures

image

FullFramework: Windows x64

I 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:

I think that different DLL name isn't testing DotnetCliToolReference, which isn't supported when targeting .NET Core 3 or higher. I think EF still uses it though, otherwise we could probably delete all those tests (and maybe even the functionality). I think we talked about this within the last year and there may be an issue filed to follow up on it.

image

TemplateEngine Windows x64

Also have no idea. It got a completely different set of table outputs with missing entries. Also, the Type and Language columns are not populated.

image

TestBuild Linux x64

This is a know test failure. We just rerun this one until it passes. Thread about it here: #50784

@333fred 333fred merged commit 0bab00a into dotnet:release/10.0.1xx Sep 23, 2025
26 of 27 checks passed
@333fred 333fred deleted the analyzer-warning branch September 24, 2025 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants