Skip to content

v3.0.3: Function parameters no longer shadowed by class defaults in typed objects

Latest

Choose a tag to compare

@jdx jdx released this 28 Sep 20:40
· 2 commits to main since this release
Immutable release. Only release title and notes can be modified.
69d7524

Fixes a name-resolution bug where a function parameter could be shadowed by an inherited class property of the same name while building a typed object. The result then differed from Apple Pkl.

Fixed

  • Function parameters now take precedence over inherited members in typed objects (#212) @jdx. Suppose a function builds an object of a class that has a property with the same name as one of the function's parameters. In 3.0.2, a reference to that name inside the object body resolved to the property's class default (often null) and not to the argument. Because of this, hk's migrated pre-commit step ran --hook-stage null instead of --hook-stage pre-commit:

    class Step { stage: String?; check: String? }
    local function precommit(stage: String): Step = new {
      check = "run --hook-stage \(stage)"
    }
    result = precommit("pre-commit")  // result.check is now "run --hook-stage pre-commit"

    This follows the same lexical-scoping rule as the 3.0.1 fix. It applies to direct function calls, object methods, apply, callbacks, pipes, and output converter calls.

Full Changelog: v3.0.2...v3.0.3