Skip to content

Cache undefined widening properties per symbol, not per name - #64728

Draft
Max Schwenk (maschwenk) wants to merge 1 commit into
microsoft:mainfrom
maschwenk:fix/undefined-property-order
Draft

Max Schwenk (maschwenk) wants to merge 1 commit into
microsoft:mainfrom
maschwenk:fix/undefined-property-order

Conversation

@maschwenk

Copy link
Copy Markdown
Contributor

Fixes #64727

getUndefinedProperty cached the synthetic prop?: undefined symbol by name, so the first object literal to widen a name decided how that property printed in later, unrelated types. declaration output then depended on which other files shared a checker, and on --checkers.

this keys the cache by the source property symbol instead. it's a 4 line change in checker.go.

  • new test undefinedPropertyDeclarationOrder covers the a.ts/b.ts repro
  • objectLiteralNormalization baselines reorder: c3, c4 and e2 now match 6.0.3 exactly, nothing moves further from it
  • emitted b.d.ts is byte-identical with and without a.ts at --checkers 1, 2, 4 and 8. before the fix it differed at 1, 2 and 4
  • hereby validate passes except test:extension, which fails the same way on clean main

ai disclosure: written with claude code. i've read the change and will handle review myself.

getUndefinedProperty cached its synthetic `prop?: undefined` symbol by
property name. The first object literal to widen a given name won, and
its declaration position decided where the property printed in later,
unrelated types. So declaration output changed depending on which other
files shared a checker, and therefore on --checkers.

Key the cache by the source property symbol instead.
@jakebailey

Copy link
Copy Markdown
Member

Unless copilot points out something I missed, this fix seems fine

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused cache-key correction is consistent with symbol identity and has appropriate regression and baseline coverage.

0 open findings

What changed in this PR

Fixes nondeterministic declaration property ordering by scoping synthetic undefined-property symbols to their source symbols.

Changes:

  • Cache undefined properties per source symbol instead of property name.
  • Add regression coverage for cross-literal cache contamination.
  • Update affected declaration, type, and symbol baselines.
File Description
tsc/​internal/​checker/​checker.go Keys undefined-property cache by source symbol.
tsc/​testdata/​tests/​cases/​compiler/​undefinedPropertyDeclarationOrder.ts Adds the regression case.
tsc/​testdata/​baselines/​reference/​compiler/​undefinedPropertyDeclarationOrder.js Records declaration output.
tsc/​testdata/​baselines/​reference/​compiler/​undefinedPropertyDeclarationOrder.types Records inferred types.
tsc/​testdata/​baselines/​reference/​compiler/​undefinedPropertyDeclarationOrder.symbols Records symbol identities.
tsc/​testdata/​baselines/​reference/​conformance/​objectLiteralNormalization.js Updates normalized declaration ordering.
tsc/​testdata/​baselines/​reference/​conformance/​objectLiteralNormalization.types Updates normalized type ordering.
tsc/​testdata/​baselines/​reference/​conformance/​objectLiteralNormalization.symbols Removes unrelated cached declarations.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

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

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TS 7: declaration emit property order depends on which other files are in the program

3 participants