Skip to content

Referring to field defined at outer most level at some inner level where duplicated field is present #1777

Answered by yannham
suimong asked this question in Q&A
Discussion options

You must be logged in to vote

The simplest work around currently is to capture the external variable in a let binding before it's shadowed:

# sample.ncl
{
  foo = 1,
  bar = {
    foo = 5,
  },
  baz = let bar_foo = bar.foo in {
    foo = 3,
    cux = foo + bar_foo + 1,
  },
}

It can sometimes become a bit verbose. Possible future solutions could include special keywords like self/super. Alternatively, a nonrec keyword to specify that we want some records to not be recursive could also be a solution.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@suimong
Comment options

Answer selected by suimong
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants