Ensure that IsRuntimeAsyncEnabledIn is propagated for closure symbols#82404
Open
333fred wants to merge 1 commit intodotnet:mainfrom
Open
Ensure that IsRuntimeAsyncEnabledIn is propagated for closure symbols#82404333fred wants to merge 1 commit intodotnet:mainfrom
333fred wants to merge 1 commit intodotnet:mainfrom
Conversation
Member
Author
|
@jcouv @RikkiGibson for a review |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes runtime-async enablement propagation when async methods are lifted into synthesized closure methods, preventing incorrect IsRuntimeAsyncEnabledIn behavior and addressing the crash reported in #82397.
Changes:
- Suppress
CS9113in the test-source definition ofRuntimeAsyncMethodGenerationAttributeto avoid unrelated diagnostics. - Add a regression test covering a runtime-async local function awaited from a non-runtime-async lambda.
- Propagate
IsRuntimeAsyncEnabledInMethodfrom the base method into synthesized closure/wrapper methods by making the source property virtual and overriding it inSynthesizedMethodBaseSymbol.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs | Suppresses CS9113 within the runtime-async attribute test definition source. |
| src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncTests.cs | Adds regression test for the crash scenario (issue #82397). |
| src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs | Makes IsRuntimeAsyncEnabledInMethod virtual so synthesized symbols can override/forward it. |
| src/Compilers/CSharp/Portable/Lowering/SynthesizedMethodBaseSymbol.cs | Overrides IsRuntimeAsyncEnabledInMethod to forward the value from BaseMethod when applicable. |
333fred
commented
Feb 13, 2026
| get { return true; } | ||
| } | ||
|
|
||
| internal sealed override ThreeState IsRuntimeAsyncEnabledInMethod => |
Member
Author
There was a problem hiding this comment.
Because this did not get propagated, methods that got lifted to closures (like a local function child of a non-runtime async lambda) did not appropriately identify themselves as runtime async, so their bodies would be rewritten with the compiler-based async rewriter and fail.
AlekseyTs
reviewed
Feb 13, 2026
| } | ||
|
|
||
| internal sealed override ThreeState IsRuntimeAsyncEnabledInMethod => | ||
| BaseMethod is SourceMethodSymbol { IsRuntimeAsyncEnabledInMethod: var value } |
Contributor
AlekseyTs
reviewed
Feb 13, 2026
| #pragma warning disable CS9113 // Unread primary constructor parameter | ||
|
|
||
| [AttributeUsage(AttributeTargets.Method)] | ||
| public class RuntimeAsyncMethodGenerationAttribute(bool runtimeAsync) : Attribute(); |
Contributor
Contributor
|
Done with review pass (commit 1) |
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.
When runtime async methods were lifted to closure methods (such as when nested inside a non-runtime async lambda), they were incorrectly leaving off IsRuntimeAsyncEnabledIn. We need to pass that through to get the right values. Fixes #82397. Test plan #75960.