Repository navigation
Also track increasing type IDs for base constraint walks - #65555
Jake Bailey (jakebailey) wants to merge 2 commits into
Conversation
A chain of ten indexed accesses reaching the same type parameter is finite, but its base constraint is lost depending on which declaration is checked first, and accessing a property of it, or of the type parameter itself, reports a false error. For 65508
Computing a base constraint gives up past ten levels of nesting once a type with the same recursion identity repeats, as a repeating pattern could be instantiated without end. The object types of a chain of indexed accesses, such as T["a"]["a"]["a"], all share the identity of T, so a chain of ten or more gave up, and accessing a property of it failed. Base constraints already resolved are not walked again, so whether a walk reached the limit depended on which declaration was checked first. A type repeats only if it is no older than the type with the same identity on the stack, as each step of an expanding instantiation is built from the step before it, whereas the object type of an indexed access is a part of it. As in isDeeplyNestedType, type ids give the order in which types were created. Fixes 65508
|
TypeScript Bot (@typescript-bot) test it |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the update to the Go checker’s base-constraint recursion guard.
No open issues 🎉
What changed in this PR
Updates the Go checker’s base-constraint recursion guard to distinguish finite indexed-access chains from expanding instantiations, addressing the false property errors reported in #65508.
Changes:
- Tracks type IDs alongside recursion identities so walks into older component types can continue.
- Adds a regression test covering ten-level indexed-access chains and declaration-order-sensitive constraint resolution.
- Adds type and symbol baselines confirming the expected property types and bindings.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/deepIndexedAccessChainConstraint.ts |
Tests constraint preservation through deep indexed-access chains. |
tsc/testdata/baselines/reference/compiler/deepIndexedAccessChainConstraint.types |
Records expected types, including string property results. |
tsc/testdata/baselines/reference/compiler/deepIndexedAccessChainConstraint.symbols |
Records expected symbol bindings for the regression test. |
tsc/internal/checker/checker.go |
Makes base-constraint repeat detection account for type-ID ordering. |
Review effort: Balanced
|
Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready. Everything looks the same! |
|
Jake Bailey (@jakebailey) Here are the results of running the user tests with tsc comparing Everything looks good! |
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Jake Bailey (@jakebailey) Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
This fix was pulled out of #65064 and reworked to work on main without the "type generation" thing.
#65520 sort of fixes this but not really, it just hides the one specific case and not the root cause.
When the checker computes a base constraint, it walks the chain of nested constraints with a stack of the recursion identities it has passed through. Past ten levels, it stops as soon as a type's recursion identity is already on the stack, since an expanding instantiation like
Foo<T>→Foo<Foo<T>>→ … could otherwise go on forever.This goes wrong for a chain of indexed accesses like
T["a"]["a"]…["a"]. Each level's object type has the recursion identity ofT, so a chain of ten or more stops the walk, even though it is finite. The base constraint is lost, and property accesses on the chain, and even onTitself, report false TS2339 errors. Base constraints already resolved aren't walked again, so whether the walk hits the limit depends on which declaration happens to be checked first.To fix this, each stack frame also records the type's id, and a type only counts as a repeat if its id is at least that of the matching frame. Type ids are assigned in creation order, as
isDeeplyNestedTypealready assumes. Each step of an expanding instantiation is created from the step before it, so it always has a higher id and still stops the walk. The object type of an indexed access is part of the access and was created before it, so its id is lower, and walking into it never counts as a repeat.Fixes #65508
Closes #65520