Oof, this is very annoying and error prone, I tried to think about it for a moment but I don't see a better way of doing that. Thank you for bringing that usecase to my attention.
For further actions, you may consider blocking this person and/or reporting abuse
Thanks for the post! Found a way to have a mutable version, too:
Spoke with Spex and Andrew and they confirmed that doing
switch (self.*)
does not create a copy, so you can do this:Diff:
*Cat
, not a*Animal
|*case|
and calling the function normallyThis would not work if
self.*
created a copy, but since it never does, it's fine.If you have *Cat, why would you need
self.cat.hp += 1;
and not:
self.hp += 1;
oh, I forgot to update that line from the original code by Zhora.
I've fixed it now, thank you.
That's neat! I'll try it, thanks ;)
Oof, this is very annoying and error prone, I tried to think about it for a moment but I don't see a better way of doing that. Thank you for bringing that usecase to my attention.