Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for lock statements within yield return state machines #2846

Merged

Conversation

ElektroKill
Copy link
Contributor

Link to issue(s) this covers:
N/A

Problem

ILSpy did not properly decompile lock statements in yield return state machines generated by the legacy C# compiler. This was due to a variation in the ILAst pattern. The difference is an extra variable.

Before changes:

public static IEnumerable<int> YieldReturnInLock1(object o)
{
	bool lockTaken = false;
	object obj2 = default(object);
	try
	{
		object obj;
		obj2 = (obj = o);
		Monitor.Enter(obj, ref lockTaken);
		yield return 1;
	}
	finally
	{
		if (lockTaken)
		{
			Monitor.Exit(obj2);
		}
	}
}

After changes:

public static IEnumerable<int> YieldReturnInLock1(object o)
{
	lock (o)
	{
		yield return 1;
	}
}

Solution

  • Added support for the ILAst pattern mentioned above
  • Enabled the previously disabled test cases for lock statements in yield return state machines.

@siegfriedpammer
Copy link
Member

Thank you for your contribution!

@siegfriedpammer siegfriedpammer merged commit 007f80a into icsharpcode:master Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants