From 8f6bf3b45bd5d714c67852ea7e1e75b5e34c082a Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Mon, 13 Jul 2020 23:53:13 +0200 Subject: [PATCH] Simplify TranslateArrayIndex. --- .../CSharp/ExpressionBuilder.cs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index ddf0e3def..ce88a7ea3 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -2301,19 +2301,14 @@ namespace ICSharpCode.Decompiler.CSharp .WithoutILInstruction().WithRR(new ByReferenceResolveResult(expr.Type, ReferenceKind.Ref)); } - TranslatedExpression TranslateArrayIndex(ILInstruction i, bool expectSystemIndex = false) + TranslatedExpression TranslateArrayIndex(ILInstruction i) { var input = Translate(i); - KnownTypeCode targetType; - if (i.ResultType == StackType.I4) { - if (input.Type.IsSmallIntegerType() && input.Type.Kind != TypeKind.Enum) { - return input; // we don't need a cast, just let small integers be promoted to int - } - targetType = input.Type.GetSign() == Sign.Unsigned ? KnownTypeCode.UInt32 : KnownTypeCode.Int32; - } else { - targetType = input.Type.GetSign() == Sign.Unsigned ? KnownTypeCode.UInt64 : KnownTypeCode.Int64; + if (i.ResultType == StackType.I4 && input.Type.IsSmallIntegerType() && input.Type.Kind != TypeKind.Enum) { + return input; // we don't need a cast, just let small integers be promoted to int } - return input.ConvertTo(compilation.FindType(targetType), this); + IType targetType = FindArithmeticType(i.ResultType, input.Type.GetSign()); + return input.ConvertTo(targetType, this); } internal static bool IsUnboxAnyWithIsInst(UnboxAny unboxAny, IsInst isInst)