Skip to content

Bound printing of deferred array and tuple references by their node - #65544

Open
Jake Bailey (jakebailey) wants to merge 1 commit into
microsoft:mainfrom
jakebailey:bound-deferred-array-printing
Open

Jake Bailey (jakebailey) wants to merge 1 commit into
microsoft:mainfrom
jakebailey:bound-deferred-array-printing

Conversation

@jakebailey

Copy link
Copy Markdown
Member

This was effectively a regression in #64556. Type references needed to be checked first.

Fixes #64683

Printing a type stops nesting once enough types with the same identity
are nested, but array and tuple types have none, so that an array
written out with finite nesting is printed in full. A recursive type
whose instantiations nest arrays through a conditional type, such as

    type G<T> = T extends unknown ? (T | G<[T]>)[] : never;

creates a new deferred array reference at each level, so printing
G<"x"> with noErrorTruncation, or in declaration emit, recursed until
the stack overflowed. A deferred array or tuple reference nests through
its node, as any other deferred reference does, so printing it stops
at the same depth as for those.

Fixes 64683

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

No active review issues block the change restoring bounded printing of deferred array and tuple references.

No open issues 🎉

What changed in this PR

Fixes #64683, a regression from #64556, by restoring bounded printing of deferred array and tuple references in the native TypeScript compiler.

Changes:

  • Checks deferred references before the array/tuple exemption, using their syntax nodes to bound recursive printing.
  • Adds an expanding recursive-type regression case with noErrorTruncation enabled.
  • Updates baselines to record bounded type output and expected diagnostics.
File Description
tsc/​testdata/​tests/​cases/​compiler/​recursiveContainerDeclarationSerialization.ts Adds regression coverage for expanding recursive types.
tsc/​testdata/​baselines/​reference/​compiler/​recursiveContainerDeclarationSerialization.types Records bounded type serialization.
tsc/​testdata/​baselines/​reference/​compiler/​recursiveContainerDeclarationSerialization.symbols Records symbols for the new test case.
tsc/​testdata/​baselines/​reference/​compiler/​recursiveContainerDeclarationSerialization.js Updates source and emitted JavaScript baselines.
tsc/​testdata/​baselines/​reference/​compiler/​recursiveContainerDeclarationSerialization.errors.txt Records serialization-limit and assignment diagnostics.
tsc/​internal/​checker/​nodebuilderimpl.go Prioritizes node-based bounds for deferred references.

Review effort: Balanced

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

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

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

Type printer recurses without limit into nested array/tuple types (stack overflow; can leave later types any)

3 participants