From 03183ab7bf562318118fac494069c409ab8d3682 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Fri, 1 Apr 2011 09:21:04 +0200 Subject: [PATCH] Fixed crash in PatternStatementTransform (foreach loop with captured variables). --- .../Ast/Transforms/PatternStatementTransform.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs b/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs index af053b107..844b223f7 100644 --- a/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs +++ b/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs @@ -176,7 +176,6 @@ namespace ICSharpCode.Decompiler.Ast.Transforms if (varDecl != null && varDecl.Parent is BlockStatement) { Statement declarationPoint; if (CanMoveVariableDeclarationIntoStatement(varDecl, usingStatement, out declarationPoint)) { - Debug.Assert(declarationPoint == usingStatement); // Moving the variable into the UsingStatement is allowed: usingStatement.ResourceAcquisition = new VariableDeclarationStatement { Type = (AstType)varDecl.Type.Clone(), @@ -302,7 +301,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms }; node.ReplaceWith(foreachStatement); foreach (Statement stmt in m.Get("variablesOutsideLoop")) { - ((BlockStatement)foreachStatement.Parent).Statements.InsertAfter(null, stmt); + ((BlockStatement)foreachStatement.Parent).Statements.InsertAfter(null, stmt.Detach()); } return foreachStatement; }