Repository navigation
Make the README inheritance sample compile and stay generic down the hierarchy [patch] - #122
Merged
Merged
Conversation
…hierarchy [patch] The three-level sample derived ColoredCircle from the concrete Circle, so its DeepClone(ColoredCircle) override failed with CS0115 and DeepClone() returned Circle. Keep the intermediate class generic and abstract, close the CRTP parameter only at the leaves, and say what goes wrong when a subclass derives from a class that already closed it. Tests mirror the sample and check README still declares it. Fixes #104 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW2HqCSuHeAzmHzLkRc
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #104
What changed
The "Inheritance and Deep Cloning" sample in
README.mdderivedColoredCirclefrom the concreteCircle : Shape<Circle>. That closesTDerivedatCircle, which causes three problems:ColoredCircle.DeepClone(ColoredCircle)failed to compile with CS0115.original.DeepClone()returnedCircle, soclone.Colorfailed to compile.I took the first option the issue offered:
Circle<T> : Shape<T>is now generic and abstract.Circle : Circle<Circle>andColoredCircle : Circle<ColoredCircle>close the parameter only at the leaves. This is the same pattern as the README'sAnimal<T>/Mammal<T>/Dogexample andMocks/BaseObject.cs.ColoredCircle clone = original.DeepClone();, which shows the clone keeps the leaf type.CreateInstance()isn't overridden, plus the covariant-return limit on runtimes before .NET 5.Tests
ReadmeInheritanceExampleTests:ColoredCircleand aCircle, then checks every level's properties and that the collections are independent.Readme_DeclaresTheTestedHierarchyandReadme_DoesNotDeriveFromAClosedCrtpClassreadREADME.mdand check it declares the hierarchy the test compiles, so the sample and the test can't drift apart. Onmain, 5 of these cases fail. With this change they pass. I checked that by stashing the README change and running them again.Full suite: 74/74 passing on net10.0.
Generated by Claude Code