From 11468135b46c6242eb47bf45e740defe37c9aedb Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 7 May 2022 07:57:15 +0200 Subject: [PATCH] Add special-case for non-primary record struct constructors --- .../TransformFieldAndConstructorInitializers.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs b/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs index 48ebc81cf..07be49c21 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs @@ -189,7 +189,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms // Recognize field or property initializers: // Translate first statement in all ctors (if all ctors have the same statement) into an initializer. bool allSame; - bool isPrimaryCtor = declaringTypeDefinition.IsReferenceType == true && declaringTypeDefinition.IsRecord; + bool isStructPrimaryCtor = false; do { Match m = fieldInitializerPattern.Match(instanceCtorsNotChainingWithThis[0].Body.FirstOrDefault()); @@ -214,12 +214,15 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms // remove record ctor parameter assignments if (!IsPropertyDeclaredByPrimaryCtor(fieldOrPropertyOrEvent as IProperty, record)) break; - isPrimaryCtor = true; + isStructPrimaryCtor = true; } else { // cannot transform if member is not found - if (fieldOrPropertyOrEventDecl == null || !isPrimaryCtor) + if (fieldOrPropertyOrEventDecl == null) + break; + // or if this is a struct record, but not the primary ctor + if (declaringTypeDefinition.IsRecord && declaringTypeDefinition.IsReferenceType == false && !isStructPrimaryCtor) break; }