Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void IStatementTransform.Run(Block block, int pos, StatementTransformContext con
{
case NewObj newObjInst:
if (newObjInst.ILStackWasEmpty && v.Kind == VariableKind.Local
&& !TypeContainsInitOnlyProperties(newObjInst.Method.DeclaringType.GetDefinition())
Comment thread
nikitalita marked this conversation as resolved.
Outdated
&& !currentMethod.IsConstructor
&& !currentMethod.IsCompilerGeneratedOrIsInCompilerGeneratedClass())
{
Expand Down Expand Up @@ -187,6 +188,18 @@ void IStatementTransform.Run(Block block, int pos, StatementTransformContext con
ILInlining.InlineIfPossible(block, pos, context);
}

private static bool TypeContainsInitOnlyProperties(ITypeDefinition? typeDefinition)
{
foreach (var property in typeDefinition?.Properties ?? [])
{
if (property.Setter?.IsInitOnly ?? false)
{
return true;
}
}
return false;
Comment thread
nikitalita marked this conversation as resolved.
}

internal static bool IsRecordCloneMethodCall(CallInstruction ci)
{
if (ci.Method.DeclaringTypeDefinition?.IsRecord != true)
Expand Down
Loading