Add comprehensive CS1622 compiler error documentation #47884
Closed
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.
This PR creates detailed documentation for CS1622 compiler error to address the misleading information identified in the issue. The original documentation suggested that iterator methods cannot use
returnstatements at all, which is incorrect.What was fixed
The CS1622 error documentation was incomplete and misleading. The current mention in
iterator-yield.mdstates that iterator methods "can't also use areturnstatement to return a sequence," but this oversimplifies the actual rules and could confuse developers.What this PR adds
Creates a new
cs1622.mdfile that provides comprehensive coverage of:Clarified rules: You cannot mix
yield returnwithreturnstatements in the same iterator method, but you CAN use a singlereturnstatement to return an object that implements the required interface (when not using anyyieldstatements).Clear examples showing both scenarios:
IAsyncEnumerable coverage: The same rules apply to async iterator methods, which was requested in the issue but not documented anywhere.
Multiple fix approaches: Practical solutions including using only yield statements, only return statements, or splitting into separate methods.
The documentation has been validated through compilation testing to ensure accuracy, and passes all markdown linting requirements.
Fixes #40067.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.
Internal previews