outer.outer.p doesn't work? #68

Open
opened 2025-12-30 01:20:21 +01:00 by adam · 2 comments
Owner

Originally created by @EvgSkv on GitHub (Feb 14, 2024).

What if I need to access a field p which is two levels up? Seems like outer.outer.p should access it, but I am getting an error.

p = "value one"

d1 {
  p = "value two"
  w = outer.p  // OK
  d2 {
    x = p // OK
    y = module.p // OK
    z = outer.outer.p  // Results in an error, but shouldn't this resolve to p which is "value one"? 
  }
}
Originally created by @EvgSkv on GitHub (Feb 14, 2024). What if I need to access a field `p` which is two levels up? Seems like `outer.outer.p` should access it, but I am getting an error. ``` p = "value one" d1 { p = "value two" w = outer.p // OK d2 { x = p // OK y = module.p // OK z = outer.outer.p // Results in an error, but shouldn't this resolve to p which is "value one"? } } ```
Author
Owner

@bioball commented on GitHub (Feb 15, 2024):

Right; outer can't be nested.

To go further out, you can add a local:

obj {
  local self = this
  obj {
    obj {
      prop = self.prop
    }
  }
}

Or, if it happens to be defined on the module level, access through module:

prop = 1

obj {
  obj {
    obj {
      prop = module.prop
    }
  }
}
@bioball commented on GitHub (Feb 15, 2024): Right; `outer` can't be nested. To go further out, you can add a `local`: ```groovy obj { local self = this obj { obj { prop = self.prop } } } ``` Or, if it happens to be defined on the module level, access through `module`: ```groovy prop = 1 obj { obj { obj { prop = module.prop } } } ```
Author
Owner

@EvgSkv commented on GitHub (Feb 15, 2024):

Is there a reason why outer can't be nested? Addressing a field two levels above seems natural. Are there plans to enable nesting?

Seems like nesting would be a good feature :-)

Thank you for your work and fast response!

@EvgSkv commented on GitHub (Feb 15, 2024): Is there a reason why outer can't be nested? Addressing a field two levels above seems natural. Are there plans to enable nesting? Seems like nesting would be a good feature :-) Thank you for your work and fast response!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#68