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

Invalid implicit enum value for unordered items #2640

Closed
mmusu3 opened this issue Mar 6, 2022 · 0 comments
Closed

Invalid implicit enum value for unordered items #2640

mmusu3 opened this issue Mar 6, 2022 · 0 comments
Labels
Bug Decompiler The decompiler engine itself

Comments

@mmusu3
Copy link

mmusu3 commented Mar 6, 2022

Input code

class EnumOrderTest
{
    enum EnumA
    {
        Item1 = 1,
        Item0 = 0
    }

    enum EnumB
    {
        Item1 = 1,
        Item0
    }

    void Test()
    {
        // This is expected to fail since EnumB.Item0 is compiled with a value of 2 following Item1.
        System.Diagnostics.Debug.Assert((int)EnumA.Item0 == (int)EnumB.Item0);
    }
}

Erroneous output

#define DEBUG
using System.Diagnostics;

internal class EnumOrderTest
{
	private enum EnumA
	{
		Item1 = 1,
		Item0 // Will be implicitly assigned the value '2'
	}

	private enum EnumB
	{
		Item1 = 1,
		Item0
	}

	private void Test()
	{
		Debug.Assert(condition: false);
	}
}

When recompiled EnumA.Item0 will have the value 2 instead of 0.

Details

Tested with ILSpy at commit d91732f.
Input code compiled in debug mode to retain the Assert.
This is a regression from when I last tested. I was previously using commit d69137a.

@mmusu3 mmusu3 added Bug Decompiler The decompiler engine itself labels Mar 6, 2022
dgrunwald pushed a commit that referenced this issue Apr 3, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Decompiler The decompiler engine itself
Projects
None yet
Development

No branches or pull requests

1 participant