Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/AsyncStreams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ public static async IAsyncEnumerable<int> CountToWithConfigureAwait(int until)
await Task.Delay(10).ConfigureAwait(continueOnCapturedContext: false);
}
}

public static async IAsyncEnumerable<int> AwaitInFinallyWithCancellation([EnumeratorCancellation] CancellationToken cancellationToken)
{
await Task.Yield();
try
{
yield return 1;
await Task.Delay(10, cancellationToken);
}
finally
{
await Task.Yield();
}
}
}

public struct TestStruct
Expand Down
11 changes: 11 additions & 0 deletions ICSharpCode.Decompiler/IL/ControlFlow/AsyncAwaitDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,11 @@ private Block CheckSetResultReturnBlock(BlockContainer blockContainer, int setRe
finalStateKnown = true;
pos++;

// [optional] stfld <>u__N(ldloc this, ldnull)
// The hoisted-local cleanup may appear either before or after the combined-tokens disposal
// (the latter is present for async iterators with an [EnumeratorCancellation] token).
MatchHoistedLocalCleanup(block, ref pos);

if (pos + 2 == block.Instructions.Count && block.MatchIfAtEndOfBlock(out var condition, out var trueInst, out var falseInst))
{
if (MatchDisposeCombinedTokens(blockContainer, condition, trueInst, falseInst, blocksAnalyzed, out var setResultAndExitBlock))
Expand Down Expand Up @@ -1088,6 +1093,12 @@ void ValidateCatchBlock()
finalState = newState;
finalStateKnown = true;
}

// [optional] stfld <>u__N(ldloc this, ldnull)
// The hoisted-local cleanup may appear either before or after the combined-tokens disposal
// (the latter is present for async iterators with an [EnumeratorCancellation] token).
MatchHoistedLocalCleanup(catchBlock, ref pos);

if (pos + 2 == catchBlock.Instructions.Count && catchBlock.MatchIfAtEndOfBlock(out var condition, out var trueInst, out var falseInst))
{
if (MatchDisposeCombinedTokens(handlerContainer, condition, trueInst, falseInst, blocksAnalyzed, out var setResultAndExitBlock))
Expand Down
Loading