diff --git a/ICSharpCode.Decompiler/Ast/NameVariables.cs b/ICSharpCode.Decompiler/Ast/NameVariables.cs index 338f0bd20..22e32d8f0 100644 --- a/ICSharpCode.Decompiler/Ast/NameVariables.cs +++ b/ICSharpCode.Decompiler/Ast/NameVariables.cs @@ -177,6 +177,10 @@ namespace ICSharpCode.Decompiler.Ast proposedName = GetNameByType(variable.Type); } + // remove any numbers from the proposed name + int number; + proposedName = SplitName(proposedName, out number); + if (!typeNames.ContainsKey(proposedName)) { typeNames.Add(proposedName, 0); } diff --git a/ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs b/ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs index 314c929b1..38d36411e 100644 --- a/ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs +++ b/ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs @@ -57,10 +57,12 @@ namespace ICSharpCode.Decompiler.Ast.Transforms Variables = { new VariableInitializer(v.Name, v.ReplacedAssignment.Right.Detach()).CopyAnnotationsFrom(v.ReplacedAssignment) } }; ExpressionStatement es = v.ReplacedAssignment.Parent as ExpressionStatement; - if (es != null) + if (es != null) { + // Note: if this crashes with 'Cannot replace the root node', check whether two variables were assigned the same name es.ReplaceWith(varDecl.CopyAnnotationsFrom(es)); - else + } else { v.ReplacedAssignment.ReplaceWith(varDecl); + } } } variablesToDeclare = null;