diff --git a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs index 9dbefdacd..463a92088 100644 --- a/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/StatementBuilder.cs @@ -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(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 return false; if (!(v.CaptureScope == null || v.CaptureScope == usingContainer)) return false; + if (!usedVariables.Add(v)) + return false; } return true; } diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs b/ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs index 5caf14f88..5ee27aea8 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/DeclareVariables.cs @@ -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;