Skip to content

Keep dependent destructuring narrowing during re-entrant checks#4606

Open
Andarist wants to merge 8 commits into
microsoft:mainfrom
Andarist:fix/reentrant-dependent-desructuring
Open

Keep dependent destructuring narrowing during re-entrant checks#4606
Andarist wants to merge 8 commits into
microsoft:mainfrom
Andarist:fix/reentrant-dependent-desructuring

Conversation

@Andarist

@Andarist Andarist commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

fixes #4572
fixes #4613

Comment on lines +13702 to +13703
// Guard parent-type resolution only; flow analysis should allow re-entrant narrowing
links.flags &^= NodeCheckFlagsInCheckIdentifier

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#2542 pushed this to the latter line - and that's what broke the reported case

But now, thanks to the introduced rootInitializer check, we just never enter this entire branch. It seems to me that thanks to that we can push back this flag reset to an earlier spot (that is required to fix one of the tests I added as part of this PR)

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.

Pull request overview

This PR addresses #4572 by adjusting how the checker preserves dependent destructuring narrowing across re-entrant checks, and adds regression coverage around dependent destructuring scenarios (including overloaded assertion functions).

Changes:

  • Update dependent destructuring narrowing logic in Checker.getNarrowedTypeOfSymbol to avoid declaration circularity while allowing re-entrant narrowing during flow analysis.
  • Add a targeted regression test for overloaded assertion + correlated destructuring narrowing (issue #4572).
  • Add additional dependent destructuring coverage (cross-file, deferred callbacks, binding element initializer) and conformance “no crash”/reference baselines for related upstream issues.

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/checker/checker.go Adjusts dependent destructuring narrowing/recursion-guard behavior during re-entrant checks.
testdata/tests/cases/compiler/controlFlowDependentDestructuringOverloadedAssertion.ts Regression for #4572 (overloaded assertion + correlated destructuring).
testdata/tests/cases/compiler/dependentDestructuringBindingElementInitializer.ts Compiler test for dependent destructuring behavior in binding element initializers.
testdata/tests/cases/compiler/dependentDestructuringCrossFilePosition.ts Compiler test ensuring dependent destructuring narrowing works across files.
testdata/tests/cases/compiler/dependentDestructuringDeferredCallback.ts Compiler test ensuring narrowing is preserved into deferred callbacks.
testdata/tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash1.ts Conformance regression to ensure dependent destructuring does not crash (upstream issue).
testdata/tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash2.ts Conformance regression to ensure dependent destructuring does not crash (upstream issue).
testdata/tests/cases/conformance/controlFlow/dependentDestructuredVariablesNoCrash3.ts Conformance regression to ensure dependent destructuring does not crash (upstream issue).
testdata/tests/cases/conformance/controlFlow/dependentDestructuredVariablesRefereinceInDeclaration1.ts Conformance coverage for dependent destructured variable references in declarations (upstream issue).
testdata/baselines/reference/compiler/controlFlowDependentDestructuringOverloadedAssertion.symbols Symbols baseline for the #4572 regression test.
testdata/baselines/reference/compiler/controlFlowDependentDestructuringOverloadedAssertion.types Types baseline for the #4572 regression test.
testdata/baselines/reference/compiler/dependentDestructuringBindingElementInitializer.symbols Symbols baseline for binding element initializer dependent destructuring.
testdata/baselines/reference/compiler/dependentDestructuringBindingElementInitializer.types Types baseline for binding element initializer dependent destructuring.
testdata/baselines/reference/compiler/dependentDestructuringCrossFilePosition.symbols Symbols baseline for cross-file dependent destructuring test.
testdata/baselines/reference/compiler/dependentDestructuringCrossFilePosition.types Types baseline for cross-file dependent destructuring test.
testdata/baselines/reference/compiler/dependentDestructuringDeferredCallback.symbols Symbols baseline for deferred callback dependent destructuring test.
testdata/baselines/reference/compiler/dependentDestructuringDeferredCallback.types Types baseline for deferred callback dependent destructuring test.
testdata/baselines/reference/conformance/dependentDestructuredVariablesNoCrash1.errors.txt Error baseline for conformance no-crash case #1.
testdata/baselines/reference/conformance/dependentDestructuredVariablesNoCrash1.js JS baseline for conformance no-crash case #1.
testdata/baselines/reference/conformance/dependentDestructuredVariablesNoCrash1.symbols Symbols baseline for conformance no-crash case #1.
testdata/baselines/reference/conformance/dependentDestructuredVariablesNoCrash1.types Types baseline for conformance no-crash case #1.
testdata/baselines/reference/conformance/dependentDestructuredVariablesNoCrash2.errors.txt Error baseline for conformance no-crash case #2.
testdata/baselines/reference/conformance/dependentDestructuredVariablesNoCrash2.js JS baseline for conformance no-crash case #2.
testdata/baselines/reference/conformance/dependentDestructuredVariablesNoCrash2.symbols Symbols baseline for conformance no-crash case #2.
testdata/baselines/reference/conformance/dependentDestructuredVariablesNoCrash2.types Types baseline for conformance no-crash case #2.
testdata/baselines/reference/conformance/dependentDestructuredVariablesNoCrash3.errors.txt Error baseline for conformance no-crash case #3.
testdata/baselines/reference/conformance/dependentDestructuredVariablesNoCrash3.js JS baseline for conformance no-crash case #3.
testdata/baselines/reference/conformance/dependentDestructuredVariablesNoCrash3.symbols Symbols baseline for conformance no-crash case #3.
testdata/baselines/reference/conformance/dependentDestructuredVariablesNoCrash3.types Types baseline for conformance no-crash case #3.
testdata/baselines/reference/conformance/dependentDestructuredVariablesRefereinceInDeclaration1.errors.txt Error baseline for “reference in declaration” conformance case.
testdata/baselines/reference/conformance/dependentDestructuredVariablesRefereinceInDeclaration1.symbols Symbols baseline for “reference in declaration” conformance case.
testdata/baselines/reference/conformance/dependentDestructuredVariablesRefereinceInDeclaration1.types Types baseline for “reference in declaration” conformance case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants