mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 14:20:35 +01:00
[PR #781] [MERGED] Fix equals/hashCode/hasCachedValue in delegating listings/mappings #731
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?
📋 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.