Fix #3908: use the async iterator element type for yield#3911
Merged
siegfriedpammer merged 1 commit intoJul 25, 2026
Merged
Conversation
Yield translation derived its target type only from synchronous enumerable interfaces, leaving async iterator yields untyped and preserving compiler boxing casts. Use the element type already recovered by the async decompiler. Assisted-by: Copilot:gpt-5.6-sol:GitHub Copilot CLI Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 86d2918e-5a24-48b4-9a86-41d331ec3720
Member
|
Thank you for your contribution! |
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.
Fixes #3908.
Problem
StatementBuilder.VisitYieldReturnderives the target element type fromIEnumerable<T>/IEnumerator<T>. For an async iterator, that lookup returns an unknown type even thoughAsyncAwaitDecompilerhas already recovered the element type.Without the target type, the compiler-generated
box Tused to store a constrained generic valuein the async iterator's current field remains visible as
(object)value. The resultingyield returnfails with CS0266 when the iterator returns an interface constraint.Solution
Use
ILFunction.AsyncReturnTypeas the element type for async iterators, falling back to theexisting synchronous enumerable lookup.
The existing expression conversion logic can then remove compiler boxing when an implicit
conversion to the recovered element type exists. No async-state-machine-specific cast rewrite is
needed.
Tests
Extended the
AsyncStreamsPretty fixture with:bool,char, and enum values,ensuring their source values remain intact.
Validation:
AsyncStreamsPretty matrix: 6 passedruntime-async
AsyncStreamsmatrix: 2 passedfull Pretty suite: 1,913 passed, 5 existing skips
Release solution build: 0 warnings, 0 errors
full solution test suite: 4,921 passed, 15 existing skips
At least one test covering the code changed