Browse Source

Merge pull request #2953 from ElektroKill/fix/issue2949

pull/2960/head
Siegfried Pammer 2 years ago committed by GitHub
parent
commit
fcb9b0e0b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/DecimalFields.cs
  2. 17
      ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

26
ICSharpCode.Decompiler.Tests/TestCases/Correctness/DecimalFields.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
// Copyright (c) 2014 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
@ -36,7 +36,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -36,7 +36,31 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Console.WriteLine(field2);
Console.WriteLine(field3);
Console.WriteLine(field4);
Console.WriteLine(IntToDecimal());
Console.WriteLine(UIntToDecimal());
Console.WriteLine(LongToDecimal());
Console.WriteLine(ULongToDecimal());
return 0;
}
public static decimal IntToDecimal()
{
return (decimal)int.MaxValue;
}
public static decimal UIntToDecimal()
{
return (decimal)uint.MaxValue;
}
public static decimal LongToDecimal()
{
return (decimal)long.MaxValue;
}
public static decimal ULongToDecimal()
{
return (decimal)ulong.MaxValue;
}
}
}

17
ICSharpCode.Decompiler/IL/Transforms/ExpressionTransforms.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// Copyright (c) 2014-2017 Daniel Grunwald
// Copyright (c) 2014-2017 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
@ -428,11 +428,18 @@ namespace ICSharpCode.Decompiler.IL.Transforms @@ -428,11 +428,18 @@ namespace ICSharpCode.Decompiler.IL.Transforms
var args = inst.Arguments;
if (args.Count == 1)
{
int val;
if (args[0].MatchLdcI4(out val))
long val;
if (args[0].MatchLdcI(out val))
{
result = new LdcDecimal(val);
return true;
var paramType = inst.Method.Parameters[0].Type.GetDefinition()?.KnownTypeCode;
result = paramType switch {
KnownTypeCode.Int32 => new LdcDecimal(new decimal(unchecked((int)val))),
KnownTypeCode.UInt32 => new LdcDecimal(new decimal(unchecked((uint)val))),
KnownTypeCode.Int64 => new LdcDecimal(new decimal(val)),
KnownTypeCode.UInt64 => new LdcDecimal(new decimal(unchecked((ulong)val))),
_ => null
};
return result is not null;
}
}
else if (args.Count == 5)

Loading…
Cancel
Save