Skip to content

Wrong decompilation of deconstruction in foreach #3453

Open
@mmusu3

Description

@mmusu3

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDecompilerThe decompiler engine itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions