mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
"Extending" class property leads to stack overflow #361
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @StefMa on GitHub (Nov 6, 2025).
My goal:
I have a class with a property.
I create a instance from this class.
The I want to re-use this instance but "extend" a property.
Like concatenate some words to an
String.Code:
I want to re-use the existing
pigeonbut modify the name.The most obviously solution to me would be to amend the pigeon:
But this leads to an:
See also: https://pkl-playground.vercel.app/?share=start-air-involved
Overriding however, works.
So I can go with this workaround:
This is a super simplified example for our use case.
I'm not sure if a "real bug" of if just hold it wrong 🫣
@HT154 commented on GitHub (Nov 6, 2025):
You're looking for this:
This also works:
Your original code resulting in a stack overflow is expected behavior.
@StefMa commented on GitHub (Nov 6, 2025):
Thanks for the fast response and the answer!
This works, but doesn't look like it uses
thispigeon what you amend, right? 🤔Its rather "just a string coming from somewhere".
Imagine having a class coming from somewhere else (e.g. from an import), the you have to do something like this:
Looks a b it cumbersome
If this is the case, and this is the "final" answer, then its fine for me.
Feel free to close it 🔒
@bioball commented on GitHub (Nov 6, 2025):
Re-iterating what @HT154 said; the way to do this is with
super, which is thethisof the parent object!@StefMa commented on GitHub (Nov 6, 2025):
🤯 This (pun intended) is actually the correct answer.
this.nameis of course referencing to this new instancename. So it's recursive. Whilesuperis the parent 🤦♂️. Yeah, it make sense now. My bad!