No way to reference function property or let binding from object that defines a property with the same name
- Dominant language
- Java
- Stars
- 11.5k
- Forks
- 402
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 20
Description
Reproduced in Pkl 0.30.0.
In my code it's a common pattern to compute an intermediate property with a `let` binding, like this:
```pkl
function frobnicate(arg: String) =
let (foo = process(arg))
new Frobnication {
foo = foo
}
```
However this naive version causes a stack overflow. Unfortunately, none of the other scoping keywords help me here:
- `this` references the `Frobnication` object being created.
- `outer` references the class/module on which `.frobnicate()` was called.
- `super` references the superclass of `Frobnication` if any.
- `module` references the containing module.
In particular, for function properties this means I have to either uglify my parameters or define aliases:
```pkl
// Shows up in Pkldoc, not great :(
function frobnicate(foo_: String) = new Frobnication {
foo = foo_
}
// Extra let binding
function frobnicate(foo: String) =
let (foo_ = foo)
new Frobnication {
foo = foo_
}
```
I'm not quite sure what a nice way to solve this is. `outer` feels 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?).
Contributor guide
Research direction
The issue names no source file, test, or entry point. Start by locating the implementation of Pkl name resolution and scoping for let bindings, function properties, and object properties; done means agreeing on a supported reference mechanism and covering the shadowing case with regression tests and documentation.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100