Skip to content

No way to reference function property or let binding from object that defines a property with the same name #1311

@sin-ack

Description

@sin-ack

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:

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:

// 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?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions