Browse Source

Fix #3423

pull/3425/head
ElektroKill 2 months ago
parent
commit
012f5812e9
No known key found for this signature in database
GPG Key ID: EE4642374F9D2B4F
  1. 21
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/EnumTests.cs
  2. 7
      ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

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

@ -1,4 +1,4 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team // Copyright (c) AlphaSierraPapa for the SharpDevelop Team
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy of this // Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software // software and associated documentation files (the "Software"), to deal in the Software
@ -28,6 +28,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
Item2 Item2
} }
public enum NoZero
{
Item1 = 1,
Item2
}
public enum OutOfOrderMembers public enum OutOfOrderMembers
{ {
Item1 = 1, Item1 = 1,
@ -135,5 +141,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{ {
return AttributeTargets.Class | AttributeTargets.Delegate; return AttributeTargets.Class | AttributeTargets.Delegate;
} }
public void EnumInNotZeroCheck(SimpleEnum value, NoZero value2)
{
if (value != SimpleEnum.Item1)
{
Console.WriteLine();
}
if (value2 != (NoZero)0)
{
Console.WriteLine();
}
}
} }
} }

7
ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

@ -1,4 +1,4 @@
// Copyright (c) 2014 Daniel Grunwald // Copyright (c) 2014 Daniel Grunwald
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy of this // Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software // software and associated documentation files (the "Software"), to deal in the Software
@ -733,9 +733,8 @@ namespace ICSharpCode.Decompiler.CSharp
} }
else else
{ {
var zero = new PrimitiveExpression(0) var zero = expressionBuilder
.WithoutILInstruction() .ConvertConstantValue(new ConstantResolveResult(Type, 0), allowImplicitConversion: true);
.WithRR(new ConstantResolveResult(expressionBuilder.compilation.FindType(KnownTypeCode.Int32), 0));
var op = negate ? BinaryOperatorType.Equality : BinaryOperatorType.InEquality; var op = negate ? BinaryOperatorType.Equality : BinaryOperatorType.InEquality;
return new BinaryOperatorExpression(Expression, op, zero.Expression) return new BinaryOperatorExpression(Expression, op, zero.Expression)
.WithoutILInstruction() .WithoutILInstruction()

Loading…
Cancel
Save