Cannot refer property defined in amended module #267

Closed
opened 2025-12-30 01:22:58 +01:00 by adam · 2 comments
Owner

Originally created by @taichi-ishitani on GitHub (Jan 26, 2025).

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
Originally created by @taichi-ishitani on GitHub (Jan 26, 2025). A pkl error is reported when refering a property defined in the amanded moudule. How to reproduce: ```pkl // foo.pkl foo_0 { v = 0 } foo_1 { v = 1 } ``` ```pkl // 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 ```
adam closed this issue 2025-12-30 01:22:58 +01:00
Author
Owner

@HT154 commented on GitHub (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: https://github.com/apple/pkl/discussions/865#discussioncomment-11640312

@HT154 commented on GitHub (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: ```pkl // 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: https://github.com/apple/pkl/discussions/865#discussioncomment-11640312
Author
Owner

@taichi-ishitani commented on GitHub (Jan 27, 2025):

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

@taichi-ishitani commented on GitHub (Jan 27, 2025): Hi @HT154 , Thank you for your reply. I understood this is expected behaviro.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/pkl#267