Improve the usability of outer #341

Open
opened 2025-12-30 01:23:41 +01:00 by adam · 1 comment
Owner

Originally created by @HT154 on GitHub (Aug 31, 2025).

cf. Peter's old notes

Currently, outer.foo literally accesses foo on outer. Instead, it should work more like super.foo, i.e., access the lexically closest foo, not necessarily on the directly enclosing object. Perhaps outer.foo should also work for method parameters and local properties, e.g. function myFunction(bar) = new { bar = outer.bar }

This is a potentially breaking change in cases like this:

class A {
  foo: String = "baz"
  b: B
}

class B {
  foo: String
}

foo: String = "bar"

a: A = new {
  b {
    foo = outer.foo
  }
}

In the current state, a.b.foo is "baz" since outer refers to a. As proposed, if outer.foo refers to the "lexically next outer" foo then a.b.foo is "bar".

Originally created by @HT154 on GitHub (Aug 31, 2025). cf. Peter's old notes > Currently, `outer.foo` literally accesses `foo` on outer. Instead, it should work more like `super.foo`, i.e., access the lexically closest `foo`, not necessarily on the directly enclosing object. Perhaps `outer.foo` should also work for method parameters and local properties, e.g. `function myFunction(bar) = new { bar = outer.bar }` This is a potentially breaking change in cases like this: ```pkl class A { foo: String = "baz" b: B } class B { foo: String } foo: String = "bar" a: A = new { b { foo = outer.foo } } ``` In the current state, `a.b.foo` is `"baz"` since `outer` refers to `a`. As proposed, if `outer.foo` refers to the "lexically next outer" `foo` then `a.b.foo` is `"bar"`.
Author
Owner

@bioball commented on GitHub (Sep 1, 2025):

This would definitely be a breaking change.

d = 5

a = (prop) {
 b {
   // currently, resolves to `6`. 
   // If changed to "lexically closest `d`", this lookup resolves to `5`.
   c = outer.d 
 }
}

prop {
  d = 6
}

I don't think this makes sense to change now. But, one paper cut here is that outer can only look up one level higher. Possibly, we should allow outer to be chained.

@bioball commented on GitHub (Sep 1, 2025): This would definitely be a breaking change. ```pkl d = 5 a = (prop) { b { // currently, resolves to `6`. // If changed to "lexically closest `d`", this lookup resolves to `5`. c = outer.d } } prop { d = 6 } ``` I don't think this makes sense to change now. But, one paper cut here is that `outer` can _only_ look up one level higher. Possibly, we should allow `outer` to be chained.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#341