Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 22, 2025

Follow-up work for await using and await foreach preview feature detection

This PR implements follow-up work from #50937 to detect preview features in await using and await foreach constructs, using the new Roslyn APIs added in dotnet/roslyn#80455.

Changes

Core Analyzer Updates:

  • Added OperationKind.Using and OperationKind.Loop to the analyzer's registered operations (building on OperationKind.Await from Update DetectPreviewFeatureAnalyzer for runtime async #50937)
  • Added abstract methods to DetectPreviewFeatureAnalyzer:
    • SymbolFromUsingOperation - handles await using declarations and statements
    • SymbolFromForEachOperation - handles await foreach loops

C# Implementation:
The C# analyzer now detects preview features in:

  • Await using declarations: await using var stream = new MemoryStream()
  • Await using statements: await using (var stream = new MemoryStream()) { }
  • Await foreach: await foreach (var item in GetItemsAsync()) { }

VB Implementation:

  • Added stub implementations for the new abstract methods (VB doesn't support runtime async yet)

Lightup Wrappers for Backward Compatibility:

  • ForEachStatementInfoWrapper - accesses MoveNextAwaitableInfo and DisposeAwaitableInfo properties
  • SemanticModelExtensions - extension methods for new GetAwaitExpressionInfo overloads

When the new Roslyn APIs (from dotnet/roslyn#80455) are not available, the lightup wrappers gracefully return defaults and no diagnostics are reported. Once the SDK updates to include those APIs, the analyzer will automatically detect preview features in the new constructs.

Tests:
Added comprehensive test cases for all scenarios. Three tests are currently marked as skipped because they require Roslyn APIs that haven't been integrated into the SDK yet:

  • VerifyRuntimeAsyncAwaitUsingDeclarationReportsDiagnostic
  • VerifyRuntimeAsyncAwaitUsingStatementReportsDiagnostic
  • VerifyRuntimeAsyncAwaitForeachReportsDiagnostic

These tests can be unskipped once the SDK updates to a version of Roslyn that includes dotnet/roslyn#80455.

Relates to test plan dotnet/roslyn#75960

Original prompt

Follow up on the work originally done in #50937 to handle await using and await foreach, using the new apis added in dotnet/roslyn#80455.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Handle await using and await foreach with new APIs Add support for await using and await foreach in DetectPreviewFeatureAnalyzer Oct 22, 2025
Copilot AI requested a review from 333fred October 22, 2025 19:05
Copilot finished work on behalf of 333fred October 22, 2025 19:05
@333fred
Copy link
Member

333fred commented Oct 22, 2025

@copilot this should have been targeted at release/10.0.2xx. Please move it over.

Copy link
Contributor Author

Copilot AI commented Oct 22, 2025

@copilot this should have been targeted at release/10.0.2xx. Please move it over.

I've rebased all the changes onto release/10.0.2xx. The PR base branch will need to be changed from main to release/10.0.2xx in the GitHub UI, as I don't have access to modify PR settings directly.

The rebased branch copilot/follow-up-await-using-foreach-rebased is ready with all the follow-up changes for await using and await foreach detection on top of the release/10.0.2xx branch which already includes PR #50937.

@copilot this should have been targeted at release/10.0.2xx. Please move it over.

I've rebased the changes onto release/10.0.2xx (commit 1b4fb68). The PR branch needs to be force-pushed to update, but I don't have permission to do force pushes.

You can either:

  1. Change the PR's base branch to release/10.0.2xx in the GitHub UI (this will show the correct diff)
  2. Manually force push the rebased branch

The rebased changes are ready locally and include all the follow-up work for await using and await foreach detection on top of #50937.

Copilot finished work on behalf of 333fred October 22, 2025 21:57
@333fred 333fred changed the base branch from main to release/10.0.2xx October 22, 2025 21:58
@333fred
Copy link
Member

333fred commented Oct 22, 2025

@copilot you did not rebase correctly. I've changed the base, please fix it up.

Copy link
Contributor Author

Copilot AI commented Oct 22, 2025

@copilot you did not rebase correctly. I've changed the base, please fix it up.

Fixed. I've properly rebased the changes onto release/10.0.2xx (commit 157771e). The branch now correctly builds on top of #50937 (commit 0bab00a) which is already in release/10.0.2xx.

The commit is ready but needs to be force-pushed to update the remote branch since the history was rewritten.

Copilot finished work on behalf of 333fred October 22, 2025 22:11
@333fred 333fred force-pushed the copilot/follow-up-await-using-foreach branch from 8a3383e to 572a41f Compare October 23, 2025 00:10
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