Skip to content

Fix indexed-access base constraint losing explicit bound across checker histories - #65520

Open
刘亦达 (zhengdaodeguL) wants to merge 1 commit into
microsoft:mainfrom
zhengdaodeguL:fix/indexed-access-base-constraint-identity-65508
Open

刘亦达 (zhengdaodeguL) wants to merge 1 commit into
microsoft:mainfrom
zhengdaodeguL:fix/indexed-access-base-constraint-identity-65508

Conversation

@zhengdaodeguL

Copy link
Copy Markdown

Checking files in sequence with a retained checker could lose the explicit
bound of a type parameter through a finite indexed-access chain, producing a
false TS2339 that depends on check order:

// a.ts
const f: typeof victim = <U extends Box>(x: U, y: { b: string }) => x.b;

// b.ts
interface Box { a: Box; b: string }
function victim<T extends Box>(
  x: T,
  y: T["a"]["a"]["a"]["a"]["a"]["a"]["a"]["a"]["a"]["a"]
): string {
  return x.b;
}

a.ts → b.ts reported TS2339 on x.b; b.ts → a.ts and b.ts alone did
not. The cause is in getResolvedBaseConstraint: indexed-access recursion
identity was unwrapped to its object, so the ten-level chain could reach the
explicit type parameter at the heuristic cutoff and turn a recursion-context
cutoff into a permanent noConstraintType answer.

This PR narrows the stack identity for that case only: when the type is an
indexed access and the existing mapped-type normalization resolves to a type
parameter, the recursion stack uses that normalized parameter's type
identity instead of its symbol. Shared relation/inference identities,
non-parameter targets, cache policy, exact cycle detection, and depth
bounds are untouched.

Added TestBaseConstraintHistory (a retained-checker integration test with
inline fixtures) covering both positive cases in all three histories plus
the negative controls: a missing property still reports TS2339, a wrong
return type still reports TS2322, and an exact self-constraint cycle still
reports TS2313 and terminates. On the base commit, exactly the two reported
a → b histories fail; with the fix, all 12 subtests pass. go test ./internal/checker/... ./internal/compiler/... and the full TestLocal
suite pass.

Credit: this fix and its test adaptation come from the issue reporter's
research. Petr Glaser (@BleedingDev) (report filed by GPT-6.1 Sol on their behalf)
validated the narrow patch in their own repository — 19 history/control
cases plus full TestLocal conformance — and explicitly left it "not a
released fix or an upstream PR", retaining the patch and tests for human
review. The patch applied here is their candidate verbatim:
https://github.com/BleedingDev/tsrs/blob/b2655bf774ecd6ae51cea37615a81d92c07a3825/tools/oracle/base-constraint-history/indexed-access-identity.patch
(validation run https://github.com/BleedingDev/tsrs/actions/runs/43655580941).
The reporter also verified that the order-independence draft #65064 does
not correctly fix this regression, so this narrow fix stands on its own.

Fixes #65508.

Copilot AI balanced review requested due to automatic review settings November 15, 2026 21:00
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 15, 2026
@typescript-automation typescript-automation Bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Nov 15, 2026

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

Status: Not started

Development

Successfully merging this pull request may close these issues.

Go checker: finite indexed-access constraint loses its explicit bound depending on prior file checking

2 participants