diff --git a/ICSharpCode.Decompiler/Ast/Transforms/ConvertConstructorCallIntoInitializer.cs b/ICSharpCode.Decompiler/Ast/Transforms/ConvertConstructorCallIntoInitializer.cs index 054d3066e..bb1335e65 100644 --- a/ICSharpCode.Decompiler/Ast/Transforms/ConvertConstructorCallIntoInitializer.cs +++ b/ICSharpCode.Decompiler/Ast/Transforms/ConvertConstructorCallIntoInitializer.cs @@ -107,6 +107,10 @@ namespace ICSharpCode.Decompiler.Ast.Transforms AstNode fieldOrEventDecl = members.FirstOrDefault(f => f.Annotation() == fieldDef); if (fieldOrEventDecl == null) break; + Expression initializer = m.Get("initializer").Single(); + // 'this'/'base' cannot be used in field initializers + if (initializer.DescendantsAndSelf.Any(n => n is ThisReferenceExpression || n is BaseReferenceExpression)) + break; allSame = true; for (int i = 1; i < instanceCtorsNotChainingWithThis.Length; i++) { @@ -116,7 +120,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms if (allSame) { foreach (var ctor in instanceCtorsNotChainingWithThis) ctor.Body.First().Remove(); - fieldOrEventDecl.GetChildrenByRole(AstNode.Roles.Variable).Single().Initializer = m.Get("initializer").Single().Detach(); + fieldOrEventDecl.GetChildrenByRole(AstNode.Roles.Variable).Single().Initializer = initializer.Detach(); } } while (allSame); }