Skip to content

Wrong decompilation of deconstruction in foreach #3453

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

Open
mmusu3 opened this issue Apr 4, 2025 · 0 comments
Open

Wrong decompilation of deconstruction in foreach #3453

mmusu3 opened this issue Apr 4, 2025 · 0 comments
Labels
Bug Decompiler The decompiler engine itself

Comments

@mmusu3
Copy link

mmusu3 commented Apr 4, 2025

Input code

using System.Collections.Immutable;

class EnumeratorDeconstructionTest
{
    struct Data
    {
        public int A;
        public int B;

        public void Deconstruct(out int a, out int b)
        {
            a = A;
            b = B;
        }
    }

    void Test(ImmutableArray<Data> array)
    {
        foreach (var item in array)
        {
            var (a, b) = item;

            Dummy(a);
        }
    }

    void Dummy(int v) { }
}

Erroneous output

using System.Collections.Immutable;

internal class EnumeratorDeconstructionTest
{
	private struct Data
	{
		public int A;

		public int B;

		public void Deconstruct(out int a, out int b)
		{
			a = A;
			b = B;
		}
	}

	private void Test(ImmutableArray<Data> array)
	{
		ImmutableArray<Data>.Enumerator enumerator = array.GetEnumerator();

		while (enumerator.MoveNext())
		{
			var (a, _) = (Data)(ref enumerator.Current);
			Dummy(a);
		}
	}

	private void Dummy(int v)
	{
	}
}

Details

Tested with ILSpy at commit fd6070d

@mmusu3 mmusu3 added Bug Decompiler The decompiler engine itself labels Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Decompiler The decompiler engine itself
Projects
None yet
Development

No branches or pull requests

1 participant