Browse Source

Fix #1747: Stack overflow when decompiling a `bool` -> `bool?` conversion.

pull/1790/head
Daniel Grunwald 6 years ago
parent
commit
968fe1468f
  1. 32
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/OverloadResolution.cs
  2. 3
      ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

32
ICSharpCode.Decompiler.Tests/TestCases/Correctness/OverloadResolution.cs

@ -33,6 +33,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -33,6 +33,7 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
ConstructorTest();
TestIndexer();
Issue1281();
Issue1747();
}
#region ConstructorTest
@ -203,6 +204,37 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness @@ -203,6 +204,37 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
}
#endregion
#region NullableValueTypes
private static void Issue1747()
{
Console.WriteLine("Issue1747:");
M1747(null);
M1747(true);
M1747(false);
M1747((bool?)true);
M1747((bool?)false);
Console.WriteLine("Issue1747, non-constant:");
bool b = Get<bool>();
M1747(b);
M1747((bool?)b);
}
private static void M1747(bool b)
{
Console.WriteLine("bool=" + b);
}
private static void M1747(bool? b)
{
Console.WriteLine("bool?=" + b);
}
static T Get<T>()
{
return default(T);
}
#endregion
#region IndexerTests
static void TestIndexer()
{

3
ICSharpCode.Decompiler/CSharp/TranslatedExpression.cs

@ -285,7 +285,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -285,7 +285,8 @@ namespace ICSharpCode.Decompiler.CSharp
}
IType utype = NullableType.GetUnderlyingType(type);
IType targetUType = NullableType.GetUnderlyingType(targetType);
if (type.IsKnownType(KnownTypeCode.Boolean) && targetUType.GetStackType().IsIntegerType()) {
if (type.IsKnownType(KnownTypeCode.Boolean) && !targetUType.IsKnownType(KnownTypeCode.Boolean)
&& targetUType.GetStackType().IsIntegerType()) {
// convert from boolean to integer (or enum)
return new ConditionalExpression(
this.Expression,

Loading…
Cancel
Save