Browse Source

Fix #3310: Filter out copy-constructor only if it's an actual record type.

pull/3314/head
Siegfried Pammer 8 months ago
parent
commit
e96605ca87
  1. 10
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstructorInitializers.cs
  2. 4
      ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs

10
ICSharpCode.Decompiler.Tests/TestCases/Pretty/ConstructorInitializers.cs

@ -137,5 +137,15 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
} }
} }
#endif #endif
public class NoRecordButCopyConstructorLike
{
private NoRecordButCopyConstructorLike parent;
public NoRecordButCopyConstructorLike(NoRecordButCopyConstructorLike parent)
{
this.parent = parent;
}
}
} }
} }

4
ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs

@ -190,11 +190,11 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
bool ctorIsUnsafe = instanceCtorsNotChainingWithThis.All(c => c.HasModifier(Modifiers.Unsafe)); 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; record = null;
// Filter out copy constructor of records // 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(); instanceCtorsNotChainingWithThis = instanceCtorsNotChainingWithThis.Where(ctor => !record.IsCopyConstructor(ctor.GetSymbol() as IMethod)).ToArray();
// Recognize field or property initializers: // Recognize field or property initializers:

Loading…
Cancel
Save