Skip to content

Commit 1fe8771

Browse files
Fixed issue described in PR #3596: Derived record classes do not necessarily declare a ToString override, as the core logic is in PrintMembers.
1 parent 588c243 commit 1fe8771

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,18 @@ private bool ComputeIsRecord()
842842
opInequality |= metadata.StringComparer.Equals(method.Name, "op_Inequality");
843843
clone |= metadata.StringComparer.Equals(method.Name, "<Clone>$");
844844
}
845-
return getEqualityContract & toString & printMembers & getHashCode & equals & opEquality & opInequality & clone;
845+
// relaxed check for toString:
846+
// record classes may have their ToString implementation only in the base class,
847+
// so we cannot check for it here, as the type hierarchy is not yet known.
848+
// usually, the existence of a "<Clone>$" and "get_EqualityContract" method should
849+
// be a good enough indicator.
850+
// in record structs we require a ToString implementation, because the PrintMembers
851+
// method needs to be called.
852+
if (isStruct && !toString)
853+
{
854+
return false;
855+
}
856+
return getEqualityContract & printMembers & getHashCode & equals & opEquality & opInequality & clone;
846857
}
847858
#endregion
848859
}

0 commit comments

Comments
 (0)