Browse Source

Fix bugs in foreach deconstruction and deconstruction declaration, if the same variable is used multiple times.

pull/2119/head
Siegfried Pammer 5 years ago
parent
commit
b1b49b5a56
  1. 3
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs

3
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -810,6 +810,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -810,6 +810,7 @@ namespace ICSharpCode.Decompiler.CSharp
var expectedType = deconstruction.Pattern.Variable.Type;
if (!NormalizeTypeVisitor.TypeErasure.EquivalentTypes(operandType, expectedType))
return false;
var usedVariables = new HashSet<ILVariable>(ILVariableEqualityComparer.Instance);
foreach (var item in deconstruction.Assignments.Instructions) {
if (!item.MatchStLoc(out var v, out var value))
return false;
@ -822,6 +823,8 @@ namespace ICSharpCode.Decompiler.CSharp @@ -822,6 +823,8 @@ namespace ICSharpCode.Decompiler.CSharp
return false;
if (!(v.CaptureScope == null || v.CaptureScope == usingContainer))
return false;
if (!usedVariables.Add(v))
return false;
}
return true;
}

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

@ -450,7 +450,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -450,7 +450,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
{
if (!inst.MatchStLoc(out var v, out var value))
return false;
if (!g.Any(vd => vd.ILVariable == v))
if (!g.Any(vd => vd.ILVariable == v && !vd.RemovedDueToCollision))
return false;
if (!usedVariables.Add(v))
return false;

Loading…
Cancel
Save