From 012f5812e952d2c8f8ce1a14083934bd21a56cbe Mon Sep 17 00:00:00 2001 From: ElektroKill Date: Sat, 15 Mar 2025 20:28:07 +0100 Subject: [PATCH] Fix #3423 --- .../TestCases/Pretty/EnumTests.cs | 21 ++++++++++++++++++- .../CSharp/TranslatedExpression.cs | 7 +++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/EnumTests.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/EnumTests.cs index f66be670d..b7cd02c5c 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/EnumTests.cs +++ b/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 // software and associated documentation files (the "Software"), to deal in the Software @@ -28,6 +28,12 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty Item2 } + public enum NoZero + { + Item1 = 1, + Item2 + } + public enum OutOfOrderMembers { Item1 = 1, @@ -135,5 +141,18 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { return AttributeTargets.Class | AttributeTargets.Delegate; } + + public void EnumInNotZeroCheck(SimpleEnum value, NoZero value2) + { + if (value != SimpleEnum.Item1) + { + Console.WriteLine(); + } + + if (value2 != (NoZero)0) + { + Console.WriteLine(); + } + } } } diff --git a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs b/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs index ad864b5ac..e40a975e0 100644 --- a/ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs +++ b/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 // software and associated documentation files (the "Software"), to deal in the Software @@ -733,9 +733,8 @@ namespace ICSharpCode.Decompiler.CSharp } else { - var zero = new PrimitiveExpression(0) - .WithoutILInstruction() - .WithRR(new ConstantResolveResult(expressionBuilder.compilation.FindType(KnownTypeCode.Int32), 0)); + var zero = expressionBuilder + .ConvertConstantValue(new ConstantResolveResult(Type, 0), allowImplicitConversion: true); var op = negate ? BinaryOperatorType.Equality : BinaryOperatorType.InEquality; return new BinaryOperatorExpression(Expression, op, zero.Expression) .WithoutILInstruction()