From a014684918c189ebb848af6faae7a96752d18667 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 17 Oct 2017 13:14:56 +0200 Subject: [PATCH] Fix regression in AssignVariableNames --- .../IL/Transforms/AssignVariableNames.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs index a8db2d911..eea8dedae 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs @@ -198,7 +198,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms } if (string.IsNullOrEmpty(proposedName)) { var proposedNameForStoresFromNewObj = variable.StoreInstructions.OfType() - .Select(expr => GetNameByType(GuessType(expr.Value, context))) + .Select(expr => GetNameByType(GuessType(variable.Type, expr.Value, context))) .Except(currentFieldNames).ToList(); if (proposedNameForStoresFromNewObj.Count == 1) { proposedName = proposedNameForStoresFromNewObj[0]; @@ -357,8 +357,11 @@ namespace ICSharpCode.Decompiler.IL.Transforms return char.ToLower(name[0]) + name.Substring(1); } - internal static IType GuessType(ILInstruction inst, ILTransformContext context) + internal static IType GuessType(IType variableType, ILInstruction inst, ILTransformContext context) { + if (!variableType.IsKnownType(KnownTypeCode.Object)) + return variableType; + switch (inst) { case NewObj newObj: return newObj.Method.DeclaringType;