Skip to content

Commit e96605c

Browse files
Fix icsharpcode#3310: Filter out copy-constructor only if it's an actual record type.
1 parent c3261a3 commit e96605c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,15 @@ public void Print()
137137
}
138138
}
139139
#endif
140+
141+
public class NoRecordButCopyConstructorLike
142+
{
143+
private NoRecordButCopyConstructorLike parent;
144+
145+
public NoRecordButCopyConstructorLike(NoRecordButCopyConstructorLike parent)
146+
{
147+
this.parent = parent;
148+
}
149+
}
140150
}
141151
}

ICSharpCode.Decompiler/CSharp/Transforms/TransformFieldAndConstructorInitializers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ void HandleInstanceFieldInitializers(IEnumerable<AstNode> members)
190190

191191
bool ctorIsUnsafe = instanceCtorsNotChainingWithThis.All(c => c.HasModifier(Modifiers.Unsafe));
192192

193-
if (!context.DecompileRun.RecordDecompilers.TryGetValue(ctorMethodDef.DeclaringTypeDefinition, out var record))
193+
if (!context.DecompileRun.RecordDecompilers.TryGetValue(declaringTypeDefinition, out var record))
194194
record = null;
195195

196196
// Filter out copy constructor of records
197-
if (record != null)
197+
if (record != null && declaringTypeDefinition.IsRecord)
198198
instanceCtorsNotChainingWithThis = instanceCtorsNotChainingWithThis.Where(ctor => !record.IsCopyConstructor(ctor.GetSymbol() as IMethod)).ToArray();
199199

200200
// Recognize field or property initializers:

0 commit comments

Comments
 (0)