Skip to content

Fix parent inference for typed properties - #2002

Open
aashish254 wants to merge 1 commit into
apple:mainfrom
aashish254:fix/inferred-parent-typed-property
Open

aashish254 wants to merge 1 commit into
apple:mainfrom
aashish254:fix/inferred-parent-typed-property

Conversation

@aashish254

Copy link
Copy Markdown
Contributor

Problem

When a nested new {} expression infers its parent from a typed property, the default is evaluated on the class prototype. If that default refers to a sibling overridden on the object being constructed, inference can trigger a constraint failure on the prototype's default value.

Change

Call the initializer directly instead of going through VmUtils.doReadMember to avoid caching the class default as the in-progress object's own value. For const or literal defaults, fall back to reading from the prototype as before.

This keeps the declared default while allowing it to see sibling overrides, and avoids the cache-poisoning edge case where a failed constraint leaves the class default cached as the object's own value.

Validation

  • ./gradlew :pkl-cli:javaExecutable — passed
  • Both new LanguageSnippetTests fixtures passed in isolation
  • ./gradlew spotlessApply — passed

Test fixtures

Fixes #1576.

Supersedes #1974 which was auto-closed by a force push on a shallow clone.

When a nested `new {}` expression infers its parent from a typed
property, the default is evaluated on the class prototype. If that
default refers to a sibling overridden on the object being constructed,
inference can trigger a constraint failure on the prototype's default
value.

Call the initializer directly instead of going through
VmUtils.doReadMember to avoid caching the class default as the
in-progress object's own value. For const or literal defaults, fall back
to reading from the prototype as before.

Add a language snippet test for the original fix (apple#1576) and a
regression test for the cache-poisoning edge case.

Fixes apple#1576.

This branch has not been deployed

No deployments
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.

Incorrect inferred parent in new {} expression

1 participant