Browse Source

Allow direct int->char casts without casting int->ushort->char.

pull/924/head
Daniel Grunwald 8 years ago
parent
commit
f2b47b4bc1
  1. 16
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  2. 1
      ICSharpCode.Decompiler/TypeSystem/TypeUtils.cs

16
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -1243,9 +1243,19 @@ namespace ICSharpCode.Decompiler.CSharp @@ -1243,9 +1243,19 @@ namespace ICSharpCode.Decompiler.CSharp
// Case 4 (left-over extension from implicit conversion) can also be handled by our caller.
return arg.WithILInstruction(inst);
}
default:
return arg.ConvertTo(GetType(inst.TargetType.ToKnownTypeCode()), this, inst.CheckForOverflow)
.WithILInstruction(inst);
default: {
// We need to convert to inst.TargetType, or to an equivalent type.
IType targetType;
if (inst.TargetType == NullableType.GetUnderlyingType(context.TypeHint).ToPrimitiveType()
&& NullableType.IsNullable(context.TypeHint) == inst.IsLifted)
{
targetType = context.TypeHint;
} else {
targetType = GetType(inst.TargetType.ToKnownTypeCode());
}
return arg.ConvertTo(targetType, this, inst.CheckForOverflow)
.WithILInstruction(inst);
}
}
}

1
ICSharpCode.Decompiler/TypeSystem/TypeUtils.cs

@ -304,6 +304,7 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -304,6 +304,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
case KnownTypeCode.Byte:
return PrimitiveType.U1;
case KnownTypeCode.UInt16:
case KnownTypeCode.Char:
return PrimitiveType.U2;
case KnownTypeCode.UInt32:
return PrimitiveType.U4;

Loading…
Cancel
Save