Fix YieldFromFinal/ReturnFromFinal being called in non-tail positions#19403
Merged
T-Gro merged 4 commits intodotnet:mainfrom Mar 8, 2026
Merged
Fix YieldFromFinal/ReturnFromFinal being called in non-tail positions#19403T-Gro merged 4 commits intodotnet:mainfrom
T-Gro merged 4 commits intodotnet:mainfrom
Conversation
Contributor
Author
|
I asked Copilot to do a comprehensive audit. It revealed a few more bugs. I'm not sure about try/with handler. It's not clear to me why it shouldn't be final. |
Contributor
❗ Release notes required
|
Contributor
Author
|
In hindsight not covering a sample seq builder in tests was a huge oversight. |
T-Gro
approved these changes
Mar 8, 2026
This was referenced Mar 8, 2026
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.
Fix
YieldFromFinal/ReturnFromFinalbeing called in non-tail positionsProblem
The
*Finalvariants (YieldFromFinal,ReturnFromFinal) were incorrectly dispatched in several non-tail-position contexts within computation expressions:forloop bodies —yield!/return!insideforwas callingYieldFromFinalinstead ofYieldFrom(regression from YieldFromFinal being called from a non-tailcall position #19402)usebindings — the body ofusewas treated as tail position, but it's wrapped inUsing/TryFinallyso it's not actually a tail calluse!bindings — same issue asuseFix
Pass
noTailCall ceenvinstead ofceenvwhen translating:ForEachbody (line 1325)usebody (line 1915)use!body (line 1979)Tests
Added a
ListBuilder— a realistic seq-like builder that useslist<'T>throughout and tracksYieldFromvsYieldFromFinalcall counts. Each test verifies both the produced result and which method variant was called.Covers 11 scenarios:
forloop bodyYieldFromYieldFromFinaltry/withbodyYieldFromtry/finallybodyYieldFromtry/withhandlerYieldFromFinalusebodyYieldFromwhilebodyYieldFrommatchbranch (tail)YieldFromFinalif/else(tail)YieldFromFinallet!continuation (tail)YieldFromFinalYieldFrom+YieldFromFinalAdded a try/with handler case in
coroutines.fsx.Fixes #19402