Stop copied settings sharing mutations of the source serialization

Merged
SI
3mo ago
+35-0

SerializationSettings is copy on write: the first serialization mutation on a VerifySettings clones the global instance and sets isCloned, after which that instance mutates its own copy in place.

The copy constructor assigned that same instance to the copy without clearing isCloned on the source, so every later mutation of the source was applied in place and observed by the copy:

settings.IgnoreMember("A");
var copy = new VerifySettings(settings);
settings.IgnoreMember("B"); // also ignored by copy

This also hit the eager copy the SettingsTask constructor takes, when the original settings were mutated between two Verify calls.

The source is now marked as no longer the exclusive owner, so it clones before its next mutation. Sharing until either side writes keeps the copy allocation free, which matters since a copy is taken per verification.