Browse Source

Fix #2640: Invalid implicit enum value for unordered items

pull/2650/head
Siegfried Pammer 3 years ago
parent
commit
1ee3384a05
  1. 6
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/EnumTests.cs
  2. 7
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

6
ICSharpCode.Decompiler.Tests/TestCases/Pretty/EnumTests.cs

@ -28,6 +28,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Item2 Item2
} }
public enum OutOfOrderMembers
{
Item1 = 1,
Item0 = 0
}
public enum LongBasedEnum : long public enum LongBasedEnum : long
{ {
Item1, Item1,

7
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -1393,7 +1393,12 @@ namespace ICSharpCode.Decompiler.CSharp
firstValue = currentValue; firstValue = currentValue;
first = false; 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, // 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. // so we can abort, and just display all values as-is.

Loading…
Cancel
Save