Closed samfeng0517 closed 3 months ago
Thanks for this well written issue.
The behavior is expected though, and here's why:
When you call .copyWith on an instance of Dog the implementation calls the Dog constructur. Because that one doesn't have the sound parameter, the copyWith function doesn't have the sound parameter. Now since the Dogs copyWith has to override the inherited Animals copyWith, that one also can't have the sound parameter, or there would be no valid override.
So generally a superclasses copyWith method only has parameters that also all subclasses have in their constructors.
Therefore you can fix it by adding the sound parameter to both Dog and Cat constructors.
Description
If I have a polymorphism like this:
I'd expect that
Animal
's copyWith will have an optional parameter 'sound' that I can assign. However it will tell you that sound is not exist.Expected Behavior
Get a copyWith that have optional parameter
Actual Behavior
Only have non optional parameter
Screen shoot