Browse Source

Type analysis for ternary ?: don't use GetBestCommonType if it doesn't match the stack type

This was causing an assertion because 'b ? intPtr1 : 0' tried to convert to System.ValueType.
pull/987/head
Daniel Grunwald 8 years ago
parent
commit
d45d65e1e4
  1. 2
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

2
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -2038,7 +2038,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -2038,7 +2038,7 @@ namespace ICSharpCode.Decompiler.CSharp
IType targetType;
if (!trueBranch.Type.Equals(SpecialType.NullType) && !falseBranch.Type.Equals(SpecialType.NullType) && !trueBranch.Type.Equals(falseBranch.Type)) {
targetType = typeInference.GetBestCommonType(new[] { trueBranch.ResolveResult, falseBranch.ResolveResult }, out bool success);
if (!success)
if (!success || targetType.GetStackType() != inst.ResultType)
targetType = compilation.FindType(inst.ResultType.ToKnownTypeCode());
} else {
targetType = trueBranch.Type.Equals(SpecialType.NullType) ? falseBranch.Type : trueBranch.Type;

Loading…
Cancel
Save