This fixes issues when a mapping/listing delegates to another mapping/listing.
The core issue is that cachedValues is not guaranteed to be the complete set of the object's members; they may be stored on the delegate instead.
Therefore, it's not correct compute hash code and equality based on cachedValues. Instead, it's better to use the getCachedValue() method, which has the correct logic for looking up the existing cached value.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/apple/pkl/pull/781
**Author:** [@bioball](https://github.com/bioball)
**Created:** 11/5/2024
**Status:** ✅ Merged
**Merged:** 11/5/2024
**Merged by:** [@bioball](https://github.com/bioball)
**Base:** `main` ← **Head:** `fix-equals-hashcode`
---
### 📝 Commits (4)
- [`64c286f`](https://github.com/apple/pkl/commit/64c286f0fe178af232b961df4dd2aafbec83d7de) Fix equals/hashCode in listings/mappings
- [`f4f196c`](https://github.com/apple/pkl/commit/f4f196cd009b054c142a3592324ea5377e7ae76b) Add fix for hasCachedValue
- [`590a4f3`](https://github.com/apple/pkl/commit/590a4f3436052fdfdb0da1850d82aed7422a6aa7) Avoid unnecessary cast
- [`7040837`](https://github.com/apple/pkl/commit/70408373c05e6809fedf3f0bba01a5a6ad0fedcb) Apply suggestions from code review
### 📊 Changes
**14 files changed** (+170 additions, -57 deletions)
<details>
<summary>View changed files</summary>
📝 `pkl-core/src/main/java/org/pkl/core/runtime/VmListing.java` (+8 -14)
📝 `pkl-core/src/main/java/org/pkl/core/runtime/VmListingOrMapping.java` (+6 -1)
📝 `pkl-core/src/main/java/org/pkl/core/runtime/VmMapping.java` (+16 -41)
📝 `pkl-core/src/main/java/org/pkl/core/runtime/VmObject.java` (+1 -1)
📝 `pkl-core/src/test/files/LanguageSnippetTests/input/api/mapping.pkl` (+8 -0)
📝 `pkl-core/src/test/files/LanguageSnippetTests/input/listings/equality.pkl` (+11 -0)
📝 `pkl-core/src/test/files/LanguageSnippetTests/input/listings/hashCode.pkl` (+32 -0)
📝 `pkl-core/src/test/files/LanguageSnippetTests/input/mappings/equality.pkl` (+11 -0)
📝 `pkl-core/src/test/files/LanguageSnippetTests/input/mappings/hashCode.pkl` (+30 -0)
📝 `pkl-core/src/test/files/LanguageSnippetTests/output/api/mapping.pcf` (+1 -0)
📝 `pkl-core/src/test/files/LanguageSnippetTests/output/listings/equality.pcf` (+1 -0)
📝 `pkl-core/src/test/files/LanguageSnippetTests/output/listings/hashCode.pcf` (+22 -0)
📝 `pkl-core/src/test/files/LanguageSnippetTests/output/mappings/equality.pcf` (+1 -0)
📝 `pkl-core/src/test/files/LanguageSnippetTests/output/mappings/hashCode.pcf` (+22 -0)
</details>
### 📄 Description
This fixes issues when a mapping/listing delegates to another mapping/listing.
The core issue is that `cachedValues` is not guaranteed to be the complete set of the object's members; they may be stored on the delegate instead.
Therefore, it's not correct compute hash code and equality based on `cachedValues`. Instead, it's better to use the `getCachedValue()` method, which has the correct logic for looking up the existing cached value.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/apple/pkl/pull/781
Author: @bioball
Created: 11/5/2024
Status: ✅ Merged
Merged: 11/5/2024
Merged by: @bioball
Base:
main← Head:fix-equals-hashcode📝 Commits (4)
64c286fFix equals/hashCode in listings/mappingsf4f196cAdd fix for hasCachedValue590a4f3Avoid unnecessary cast7040837Apply suggestions from code review📊 Changes
14 files changed (+170 additions, -57 deletions)
View changed files
📝
pkl-core/src/main/java/org/pkl/core/runtime/VmListing.java(+8 -14)📝
pkl-core/src/main/java/org/pkl/core/runtime/VmListingOrMapping.java(+6 -1)📝
pkl-core/src/main/java/org/pkl/core/runtime/VmMapping.java(+16 -41)📝
pkl-core/src/main/java/org/pkl/core/runtime/VmObject.java(+1 -1)📝
pkl-core/src/test/files/LanguageSnippetTests/input/api/mapping.pkl(+8 -0)📝
pkl-core/src/test/files/LanguageSnippetTests/input/listings/equality.pkl(+11 -0)📝
pkl-core/src/test/files/LanguageSnippetTests/input/listings/hashCode.pkl(+32 -0)📝
pkl-core/src/test/files/LanguageSnippetTests/input/mappings/equality.pkl(+11 -0)📝
pkl-core/src/test/files/LanguageSnippetTests/input/mappings/hashCode.pkl(+30 -0)📝
pkl-core/src/test/files/LanguageSnippetTests/output/api/mapping.pcf(+1 -0)📝
pkl-core/src/test/files/LanguageSnippetTests/output/listings/equality.pcf(+1 -0)📝
pkl-core/src/test/files/LanguageSnippetTests/output/listings/hashCode.pcf(+22 -0)📝
pkl-core/src/test/files/LanguageSnippetTests/output/mappings/equality.pcf(+1 -0)📝
pkl-core/src/test/files/LanguageSnippetTests/output/mappings/hashCode.pcf(+22 -0)📄 Description
This fixes issues when a mapping/listing delegates to another mapping/listing.
The core issue is that
cachedValuesis not guaranteed to be the complete set of the object's members; they may be stored on the delegate instead.Therefore, it's not correct compute hash code and equality based on
cachedValues. Instead, it's better to use thegetCachedValue()method, which has the correct logic for looking up the existing cached value.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.