Browse Source

Fix #2407: Operator '-' cannot be applied to operand of type 'nuint'

pull/2412/head
Daniel Grunwald 4 years ago
parent
commit
f327668928
  1. 5
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/NativeInts.cs
  2. 4
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

5
ICSharpCode.Decompiler.Tests/TestCases/Pretty/NativeInts.cs

@ -200,5 +200,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -200,5 +200,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
intptr = intPtr;
i = num + 1;
}
public nint NegateUnsigned(nuint x)
{
return (nint)(0 - x);
}
}
}

4
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -1526,9 +1526,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1526,9 +1526,9 @@ namespace ICSharpCode.Decompiler.CSharp
{
IType rightUType = NullableType.GetUnderlyingType(right.Type);
if (rightUType.IsKnownType(KnownTypeCode.Int32) || rightUType.IsKnownType(KnownTypeCode.Int64)
|| rightUType.IsCSharpSmallIntegerType() || rightUType.IsCSharpNativeIntegerType())
|| rightUType.IsCSharpSmallIntegerType() || rightUType.Kind == TypeKind.NInt)
{
// unary minus is supported on signed int and long, and on the small integer types (since they promote to int)
// unary minus is supported on signed int, nint and long, and on the small integer types (since they promote to int)
var uoe = new UnaryOperatorExpression(UnaryOperatorType.Minus, right.Expression);
uoe.AddAnnotation(inst.CheckForOverflow ? AddCheckedBlocks.CheckedAnnotation : AddCheckedBlocks.UncheckedAnnotation);
var resultType = FindArithmeticType(inst.RightInputType, Sign.Signed);

Loading…
Cancel
Save