diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstructorInitializers.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstructorInitializers.cs index 7e8650ff65..9df380be97 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstructorInitializers.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstructorInitializers.cs @@ -137,5 +137,15 @@ public void Print() } } #endif + + public class NoRecordButCopyConstructorLike + { + private NoRecordButCopyConstructorLike parent; + + public NoRecordButCopyConstructorLike(NoRecordButCopyConstructorLike parent) + { + this.parent = parent; + } + } } } diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs b/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs index 8bcf924fa8..bce3b1071b 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs @@ -190,11 +190,11 @@ void HandleInstanceFieldInitializers(IEnumerable members) bool ctorIsUnsafe = instanceCtorsNotChainingWithThis.All(c => c.HasModifier(Modifiers.Unsafe)); - if (!context.DecompileRun.RecordDecompilers.TryGetValue(ctorMethodDef.DeclaringTypeDefinition, out var record)) + if (!context.DecompileRun.RecordDecompilers.TryGetValue(declaringTypeDefinition, out var record)) record = null; // Filter out copy constructor of records - if (record != null) + if (record != null && declaringTypeDefinition.IsRecord) instanceCtorsNotChainingWithThis = instanceCtorsNotChainingWithThis.Where(ctor => !record.IsCopyConstructor(ctor.GetSymbol() as IMethod)).ToArray(); // Recognize field or property initializers: