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

Wrong decompilation of record struct without primary constructor #3406

Open
mmusu3 opened this issue Feb 21, 2025 · 0 comments
Open

Wrong decompilation of record struct without primary constructor #3406

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

Comments

@mmusu3
Copy link

mmusu3 commented Feb 21, 2025

Input code

class RecordStructTests
{
    record struct S1(int Value);

    record struct S2
    {
        public int Value;

        public S2(int value)
        {
            Value = value;
        }

        public S2(int a, int b)
        {
            Value = a + b;
        }
    }

    record struct S3
    {
        public int Value;

        public S3(int value)
        {
            Value = value;
        }
    }

    // This also generates a hidden backing field
    record struct S4(int value)
    {
        public int Value = value;
    }
}

Erroneous output

internal class RecordStructTests
{
	private record struct S1(int Value);

	private record struct S2(int value) // This primary constructor should not be here
	{
		public int Value;

		public S2(int value)
		{
			Value = value;
		}

		public S2(int a, int b)
		{
			Value = a + b;
		}
	}

	private record struct S3(int value) // This primary constructor should not be here
	{
		public int Value = value;

		// Missing constructor
	}

	private record struct S4(int value) // This primary constructor is expected
	{
		public int Value = value;
	}
}

This one was tricky to find because the compiler/language behavior is not intuitive.

Details

@mmusu3 mmusu3 added Bug Decompiler The decompiler engine itself labels Feb 21, 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