Skip to content

Ensure that IsRuntimeAsyncEnabledIn is propagated for closure symbols#82404

Open
333fred wants to merge 1 commit intodotnet:mainfrom
333fred:runtime-async-propagate
Open

Ensure that IsRuntimeAsyncEnabledIn is propagated for closure symbols#82404
333fred wants to merge 1 commit intodotnet:mainfrom
333fred:runtime-async-propagate

Conversation

@333fred
Copy link
Member

@333fred 333fred commented Feb 13, 2026

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.

@333fred 333fred requested a review from a team as a code owner February 13, 2026 20:35
@333fred
Copy link
Member Author

333fred commented Feb 13, 2026

@jcouv @RikkiGibson for a review

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 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 CS9113 in the test-source definition of RuntimeAsyncMethodGenerationAttribute to avoid unrelated diagnostics.
  • Add a regression test covering a runtime-async local function awaited from a non-runtime-async lambda.
  • Propagate IsRuntimeAsyncEnabledInMethod from the base method into synthesized closure/wrapper methods by making the source property virtual and overriding it in SynthesizedMethodBaseSymbol.

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.

get { return true; }
}

internal sealed override ThreeState IsRuntimeAsyncEnabledInMethod =>
Copy link
Member Author

Choose a reason for hiding this comment

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

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.

@jcouv jcouv self-assigned this Feb 13, 2026
}

internal sealed override ThreeState IsRuntimeAsyncEnabledInMethod =>
BaseMethod is SourceMethodSymbol { IsRuntimeAsyncEnabledInMethod: var value }
Copy link
Contributor

Choose a reason for hiding this comment

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

BaseMethod is SourceMethodSymbol { IsRuntimeAsyncEnabledInMethod: var value }

Perhaps this logic should be conditioned on InheritsBaseMethodAttributes?

#pragma warning disable CS9113 // Unread primary constructor parameter

[AttributeUsage(AttributeTargets.Method)]
public class RuntimeAsyncMethodGenerationAttribute(bool runtimeAsync) : Attribute();
Copy link
Contributor

Choose a reason for hiding this comment

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

public class RuntimeAsyncMethodGenerationAttribute(bool runtimeAsync) : Attribute()

Consider restoring the warning mode after this in case the string will be concatenated with other source.

@AlekseyTs
Copy link
Contributor

Done with review pass (commit 1)

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.

Compiler crashes on local method opted into runtime async

3 participants