Skip to content

Commit

Permalink
Fix #2640: Invalid implicit enum value for unordered items
Browse files Browse the repository at this point in the history
(cherry picked from commit 1ee3384)
  • Loading branch information
siegfriedpammer authored and dgrunwald committed Apr 3, 2022
1 parent 732d82b commit daa0b9c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ICSharpCode.Decompiler.Tests/TestCases/Pretty/EnumTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public enum SimpleEnum
Item2
}

public enum OutOfOrderMembers
{
Item1 = 1,
Item0 = 0
}

public enum LongBasedEnum : long
{
Item1,
Expand Down
7 changes: 6 additions & 1 deletion ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,12 @@ EnumValueDisplayMode DetectBestEnumValueDisplayMode(ITypeDefinition typeDef, PEF
firstValue = currentValue;
first = false;
}
else if (!allConsecutive && !allPowersOfTwo)
else if (currentValue < previousValue)
{
// If the values are out of order, we fallback to displaying all values.
return EnumValueDisplayMode.All;
}
else if ((!allConsecutive && !allPowersOfTwo))
{
// We already know that the values are neither consecutive nor all powers of 2,
// so we can abort, and just display all values as-is.
Expand Down

0 comments on commit daa0b9c

Please sign in to comment.