Skip to content

Cannot refer property defined in amended module #909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
taichi-ishitani opened this issue Jan 26, 2025 · 2 comments
Closed

Cannot refer property defined in amended module #909

taichi-ishitani opened this issue Jan 26, 2025 · 2 comments

Comments

@taichi-ishitani
Copy link
Contributor

A pkl error is reported when refering a property defined in the amanded moudule.

How to reproduce:

// foo.pkl
foo_0 {
  v = 0
}
foo_1 {
  v = 1
}
// bar.pkl
amends "foo.pkl"
foo_1 {
  v = foo_0.v
}

Evaluate the above pkl code (bar.pkl) then report the error message below.

$ ../pkl --version
Pkl 0.27.2 (Linux 5.15.0-1057-aws, native)
$ ../pkl eval bar.pkl 
–– Pkl Error ––
Cannot find property `foo_0`.

4 | v = foo_0.v
        ^^^^^
at bar#foo_1.v (file:///home/taichi/temp/pkl/test/bar.pkl, line 4)

Did you mean any of the following?
foo_1
@HT154
Copy link
Contributor

HT154 commented Jan 26, 2025

This is expected behavior and the intentional design of Pkl's scoping rules. In short, this is designed to prevent unintentional changes to name resolution. In this case, the correct (and unambiguous) way to do this looks like this:

// bar.pkl
amends "foo.pkl"
foo_1 {
  v = module.foo_0.v
}

This post from @bioball goes into more detail about a similar case with the same motivation: #865 (comment)

@taichi-ishitani
Copy link
Contributor Author

Hi @HT154 ,
Thank you for your reply.
I understood this is expected behaviro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants