This repository was archived by the owner on Aug 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 239
Async state machine incorrect translation #1041
Copy link
Copy link
Open
Labels
Description
We have one more issue with incorrect goto translation in Roslyn compiled state machine. Issue only reproducible within assemblies compiled with optimizations.
Test case:
//@useroslyn
//@compileroption /optimize
using System;
using System.Threading;
using System.Threading.Tasks;
public static class Program
{
public static void Main(string[] args)
{
var signal = new ManualResetEventSlim(false);
var task = AsyncMethod(signal);
signal.Wait();
}
public static async Task AsyncMethod(ManualResetEventSlim resetEvent)
{
await new Test().FailedMethod();
resetEvent.Set();
}
}
public class Test
{
public async Task FailedMethod () {
using (await GetLockObject()) {
}
using (await GetLockObject()) {
await DoWork();
}
}
private async Task DoWork()
{
Console.WriteLine("work");
}
public async Task<IDisposable> GetLockObject()
{
Console.WriteLine("Lock");
return new LockObject();
}
}
public class LockObject : IDisposable
{
public void Dispose()
{
Console.WriteLine("Dispose");
}
}
Method that translated incorrect:
public async Task FailedMethod () {
using (await GetLockObject()) {
}
using (await GetLockObject()) {
await DoWork();
}
}
Expected output: Lock\nDispose\nLock\nwork\nDispose
Actualoutput: Lock\nwork\nDispose
Reactions are currently unavailable