Browse Source

Fix #2983: display-class locals should be named uniquely per top-level ILFunction. Add assertion to ResolveCollisions: ensure that colliding/merged variables have the same type.

pull/2971/head
Siegfried Pammer 2 years ago
parent
commit
539925f259
  1. 1
      ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs
  2. 3
      ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs

1
ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs

@ -476,6 +476,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
Debug.Assert(point1.level == point2.level); Debug.Assert(point1.level == point2.level);
if (point1.nextNode.Parent == point2.nextNode.Parent) if (point1.nextNode.Parent == point2.nextNode.Parent)
{ {
Debug.Assert(prev.Type.Equals(v.Type));
// We found a collision! // We found a collision!
v.InvolvedInCollision = true; v.InvolvedInCollision = true;
prev.ReplacementDueToCollision = v; prev.ReplacementDueToCollision = v;

3
ICSharpCode.Decompiler/IL/Transforms/AssignVariableNames.cs

@ -58,6 +58,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
Dictionary<MethodDefinitionHandle, string> localFunctionMapping; Dictionary<MethodDefinitionHandle, string> localFunctionMapping;
HashSet<ILVariable> loopCounters; HashSet<ILVariable> loopCounters;
const char maxLoopVariableName = 'n'; const char maxLoopVariableName = 'n';
int numDisplayClassLocals;
public void Run(ILFunction function, ILTransformContext context) public void Run(ILFunction function, ILTransformContext context)
{ {
@ -151,6 +152,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
AddExistingName(reservedVariableNames, p.Name); AddExistingName(reservedVariableNames, p.Name);
} }
} }
numDisplayClassLocals = 0;
foreach (ILFunction f in function.Descendants.OfType<ILFunction>().Reverse()) foreach (ILFunction f in function.Descendants.OfType<ILFunction>().Reverse())
{ {
PerformAssignment(f); PerformAssignment(f);
@ -195,7 +197,6 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{ {
// remove unused variables before assigning names // remove unused variables before assigning names
function.Variables.RemoveDead(); function.Variables.RemoveDead();
int numDisplayClassLocals = 0;
Dictionary<int, string> assignedLocalSignatureIndices = new Dictionary<int, string>(); Dictionary<int, string> assignedLocalSignatureIndices = new Dictionary<int, string>();
foreach (var v in function.Variables.OrderBy(v => v.Name)) foreach (var v in function.Variables.OrderBy(v => v.Name))
{ {

Loading…
Cancel
Save