mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Entry of which key is same with an element index #124
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @taichi-ishitani on GitHub (Mar 25, 2024).
Hi,
As shown example below, entries of which key matches with an element index will be deleted.
On the other hand, entries of which key does not match with an element index will not be deleted.
Which behavior is wrong?
@bioball commented on GitHub (Mar 25, 2024):
Currently, there is a bug when mixing entries whose keys are integers with elements. So, the first snippet is incorrect, and is a bug.
This happens because Pkl mistakenly interprets
[0] = 2as "assign to element with index 0", instead of "declare an entry with key 0".@taichi-ishitani commented on GitHub (Mar 26, 2024):
Thank you and I understood.
For the first example, what is the expected value of
foo[0]? Should it return the element with index 0?@odenix commented on GitHub (Mar 26, 2024):
What does
[n] = xmean forDynamic? Does it mean the same as forListing, the same as forMapping, or something else?@bioball commented on GitHub (Mar 27, 2024):
Currently, the behavior is: if there is an element at index
n,[n] = xmeans: overwrite element at that index. Andfoo[0]means either "get element with index 0`, or "get entry with key 0", depending on which exists. In our current model, it is not possible to for entries with number keys to coexist with elements at the same number index.With our current behavior, I think this should throw with a duplicate member definition error. It doesn't make sense for this to be accepted as one element declaration:
I think there's some room for improvement here. This is surprising:
This produces:
Possibly, we can change the grammar for "assign to element index N", which might help here. For example, here's some made up syntax:
@taichi-ishitani commented on GitHub (Mar 28, 2024):
Is it expected behavior that Pkl raise an error if an entry and an element have the same idnex?
I'm developing a Pkl parser written in Ruby so I post this issue.
@odenix commented on GitHub (Nov 5, 2024):
Pkl's behavior for dynamic objects that contain both elements and integer-keyed entries is confusing. I think it cannot even be reasoned about because a key with index
xand entry with keyxwill cause a collision inVmObject.cachedValues.I can think of several solutions, but one stands out for being simple to understand and implement:
This would also solve the following oddities:
defaults for themListingandMappinghave alengthproperty, butDynamicdoesn'tAre there legitimate use cases for supporting dynamic objects that contain both elements and entries?