Skip to content

Commit

Permalink
Fix #3310: Filter out copy-constructor only if it's an actual record …
Browse files Browse the repository at this point in the history
…type.
  • Loading branch information
siegfriedpammer committed Oct 24, 2024
1 parent c3261a3 commit e96605c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,15 @@ public void Print()
}
}
#endif

public class NoRecordButCopyConstructorLike
{
private NoRecordButCopyConstructorLike parent;

public NoRecordButCopyConstructorLike(NoRecordButCopyConstructorLike parent)
{
this.parent = parent;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ void HandleInstanceFieldInitializers(IEnumerable<AstNode> 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:
Expand Down

0 comments on commit e96605c

Please sign in to comment.