mirror of
https://github.com/apple/pkl.git
synced 2026-01-13 23:23:37 +01:00
No way to reference function property or let binding from object that defines a property with the same name #363
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 @sin-ack on GitHub (Nov 7, 2025).
Reproduced in Pkl 0.30.0.
In my code it's a common pattern to compute an intermediate property with a
letbinding, like this:However this naive version causes a stack overflow. Unfortunately, none of the other scoping keywords help me here:
thisreferences theFrobnicationobject being created.outerreferences the class/module on which.frobnicate()was called.superreferences the superclass ofFrobnicationif any.modulereferences the containing module.In particular, for function properties this means I have to either uglify my parameters or define aliases:
I'm not quite sure what a nice way to solve this is.
outerfeels like the closest candidate that should work for this purpose, but it might mean that logically, an "intermediate" object is created which represents the method's scope (closure?).@bioball commented on GitHub (Nov 7, 2025):
Using an underscore is the normal way to do this. Currently, there's no way to disambiguate referencing the function parameter.
By the way, as an aside: it's also not recommended to have "builder" methods that simply return new object instances. Typically, you would just create those objects directly instead.
@sin-ack commented on GitHub (Nov 7, 2025):
The function does much more than shown here, which is why it's done in this way. It computes a bunch of stuff from the given arguments.
@bioball commented on GitHub (Nov 7, 2025):
Makes sense!