Browse Source

Fixed bug in variable naming that could cause two variables to be assigned the same name (and subsequently triggering a crash in DeclareVariables).

pull/129/head 1.0-M2
Daniel Grunwald 14 years ago
parent
commit
0b0bcdd19f
  1. 4
      ICSharpCode.Decompiler/Ast/NameVariables.cs
  2. 6
      ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs

4
ICSharpCode.Decompiler/Ast/NameVariables.cs

@ -177,6 +177,10 @@ namespace ICSharpCode.Decompiler.Ast @@ -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);
}

6
ICSharpCode.Decompiler/Ast/Transforms/DeclareVariables.cs

@ -57,12 +57,14 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -57,12 +57,14 @@ 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;
}

Loading…
Cancel
Save