Browse Source

Fixed unintended interaction between object initializers and anonymous methods.

pull/144/head
Daniel Grunwald 14 years ago
parent
commit
baa05b2e01
  1. 4
      ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs
  2. 5
      ICSharpCode.Decompiler/ILAst/InitializerPeepholeTransforms.cs

4
ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs

@ -111,6 +111,8 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
{
if (!context.Settings.AnonymousMethods)
return false; // anonymous method decompilation is disabled
if (target != null && !(target is IdentifierExpression || target is ThisReferenceExpression || target is NullReferenceExpression))
return false; // don't copy arbitrary expressions, deal with identifiers only
// Anonymous methods are defined in the same assembly
MethodDefinition method = methodRef.ResolveWithinSameModule();
@ -175,7 +177,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
return true;
}
static bool IsPotentialClosure(DecompilerContext context, TypeDefinition potentialDisplayClass)
internal static bool IsPotentialClosure(DecompilerContext context, TypeDefinition potentialDisplayClass)
{
if (potentialDisplayClass == null || !potentialDisplayClass.IsCompilerGeneratedOrIsInCompilerGeneratedClass())
return false;

5
ICSharpCode.Decompiler/ILAst/InitializerPeepholeTransforms.cs

@ -164,6 +164,11 @@ namespace ICSharpCode.Decompiler.ILAst
return false;
} else {
// Object Initializer
// don't use object initializer syntax for closures
if (Ast.Transforms.DelegateConstruction.IsPotentialClosure(context, ctor.DeclaringType.ResolveWithinSameModule()))
return false;
initializer = new ILExpression(ILCode.InitObject, null, newObjExpr);
pos++;
while (pos < body.Count) {

Loading…
Cancel
Save