From d805e07ffe9108fc49c4ed83b729f67599f703df Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 10 Apr 2011 23:04:05 +0200 Subject: [PATCH] Fixed decompilation of nested lambdas. --- .../Ast/Transforms/DelegateConstruction.cs | 8 +++++++- .../Ast/Transforms/PatternStatementTransform.cs | 2 +- ICSharpCode.Decompiler/Tests/DelegateConstruction.cs | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs b/ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs index 6203164ce..73032d034 100644 --- a/ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs @@ -177,7 +177,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms static bool IsPotentialClosure(DecompilerContext context, TypeDefinition potentialDisplayClass) { - if (potentialDisplayClass == null || !potentialDisplayClass.IsCompilerGenerated()) + if (potentialDisplayClass == null || !potentialDisplayClass.IsCompilerGeneratedOrIsInCompilerGeneratedClass()) return false; // check that methodContainingType is within containingType while (potentialDisplayClass != context.CurrentType) { @@ -293,7 +293,13 @@ namespace ICSharpCode.Decompiler.Ast.Transforms if (!ok) continue; Dictionary dict = new Dictionary(); + // Delete the variable declaration statement: + VariableDeclarationStatement displayClassVarDecl = PatternStatementTransform.FindVariableDeclaration(stmt, variable.Name); + if (displayClassVarDecl != null) + displayClassVarDecl.Remove(); + + // Delete the assignment statement: AstNode cur = stmt.NextSibling; stmt.Remove(); diff --git a/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs b/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs index 1f9951789..60dc71de2 100644 --- a/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs +++ b/ICSharpCode.Decompiler/Ast/Transforms/PatternStatementTransform.cs @@ -201,7 +201,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms return null; } - VariableDeclarationStatement FindVariableDeclaration(AstNode node, string identifier) + internal static VariableDeclarationStatement FindVariableDeclaration(AstNode node, string identifier) { while (node != null) { while (node.PrevSibling != null) { diff --git a/ICSharpCode.Decompiler/Tests/DelegateConstruction.cs b/ICSharpCode.Decompiler/Tests/DelegateConstruction.cs index b16b0fd94..248337da2 100644 --- a/ICSharpCode.Decompiler/Tests/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/Tests/DelegateConstruction.cs @@ -157,4 +157,9 @@ public static class DelegateConstruction } }; } + + public static Func> CurriedAddition(int a) + { + return b => c => a + b + c; + } }