Skip to content

Respect fixed and const properties when converting Map or Dynamic to Typed - #1814

Open
nileshpatil6 wants to merge 2 commits into
apple:mainfrom
nileshpatil6:fix-toTyped-fixed-property
Open

Respect fixed and const properties when converting Map or Dynamic to Typed#1814
nileshpatil6 wants to merge 2 commits into
apple:mainfrom
nileshpatil6:fix-toTyped-fixed-property

Conversation

@nileshpatil6

Copy link
Copy Markdown

Reopens #1733. I accidentally closed that PR permanently by deleting my fork while cleaning up old repos, sorry for the churn. Same two commits, rebased onto current main (VmClass.java had not changed upstream, so the rebase was clean).

Recap of where the review stood:

  • .toTyped() copied whatever value the source Dynamic/Map happened to contain into fixed properties, silently overriding the class declaration. Fixed by skipping such properties during conversion in VmClass.createDelegatingMembers, so the class's own value wins.
  • @HT154 then showed the same bug applies to const properties. The second commit switches the check to the existing Member.isConstOrFixed(), matching how GeneratorMemberNode and SpecializedObjectLiteralNode already treat const and fixed as one category for override protection. Snippet tests cover both cases in map.pkl and dynamic.pkl.
  • Open question from the review, unchanged: whether an override attempt should silently drop (current behavior of this PR) or hard-error like typed literal assignment does. @HT154 wanted input from other maintainers on that, and I'm happy to switch to erroring if that's the consensus.

Re-verified after the rebase: ./gradlew :pkl-core:test --tests "*LanguageSnippetTests*" passes, the api input dir reports 158 tests, 0 failures.

DCO sign-off is on both commits.

toTyped() on Map and Dynamic built its delegating members the same
way for every property, including ones marked fixed. That let a
caller supply any value for a fixed property through the source
Map or Dynamic, silently overriding the value fixed by the class
declaration.

createDelegatingMembers is now told whether it is building members
for a conversion into Typed. When that is the case, fixed
properties are skipped just like hidden properties already are, so
the class prototype's own fixed value is used instead of whatever
is in the source Map or Dynamic. The Typed to Dynamic direction is
unaffected since it already reads from the evaluated Typed value.

Added snippet tests in map.pkl and dynamic.pkl covering toTyped()
on a class with a fixed property.

Fixes apple#573

Signed-off-by: nileshpatil6 <technil6436@gmail.com>
const properties have the same override-immunity requirement as fixed
properties: a value supplied by the source Map/Dynamic must not replace
the class's own declared value. Change the isFixed() check in
createDelegatingMembers to isConstOrFixed(), and add matching test
cases alongside the existing fixed ones in map.pkl and dynamic.pkl.

Signed-off-by: nileshpatil6 <technil6436@gmail.com>
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

Successfully merging this pull request may close these issues.

1 participant