Skip to content

[WIP] Fix regression in 6.0: Broader type inference issue#63310

Open
Copilot wants to merge 3 commits intomainfrom
copilot/fix-narrow-inference-regression
Open

[WIP] Fix regression in 6.0: Broader type inference issue#63310
Copilot wants to merge 3 commits intomainfrom
copilot/fix-narrow-inference-regression

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 27, 2026

  • Investigate root cause: PR Improve inference by not considering thisless functions to be context-sensitive #62243 removed PropertyDeclaration from ContainerFlags.IsControlFlowContainer in binder.ts
  • Root cause confirmed: property initializers no longer have isolated flow scopes, causing module-level narrowing (const DEFAULT: AB = 'A'"A") to leak into class property type inference
  • Remove debug code from checker.ts
  • Fix: restore PropertyDeclaration as IsControlFlowContainer in binder.ts
  • Add regression test classPropertyInferenceFromBroaderTypeConst.ts
  • Verify test passes with correct types (D: AB, this.D: AB)
  • Run full test suite

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits March 28, 2026 00:13
Agent-Logs-Url: https://github.com/microsoft/TypeScript/sessions/c865d3f5-aaf0-4dfc-8051-47e4fe1b3e86

Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot AI requested a review from RyanCavanaugh March 28, 2026 00:31
Copilot stopped work on behalf of RyanCavanaugh due to an error March 28, 2026 00:31
return ContainerFlags.IsControlFlowContainer;

case SyntaxKind.PropertyDeclaration:
return (node as PropertyDeclaration).initializer ? ContainerFlags.IsControlFlowContainer : ContainerFlags.None;
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.

It would be worth rechecking if this now shouldn't include PropagatesThisKeyword too

@RyanCavanaugh
Copy link
Copy Markdown
Member

@typescript-bot test it

@typescript-bot
Copy link
Copy Markdown
Collaborator

typescript-bot commented Mar 28, 2026

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top400 ✅ Started ✅ Results
user test this ✅ Started ✅ Results
run dt ✅ Started ✅ Results
perf test this faster ✅ Started 👀 Results

@typescript-bot
Copy link
Copy Markdown
Collaborator

Hey @RyanCavanaugh, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Copy Markdown
Collaborator

@RyanCavanaugh Here are the results of running the user tests with tsc comparing main and refs/pull/63310/merge:

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Git clone failed"

Otherwise...

Everything looks good!

@RyanCavanaugh RyanCavanaugh marked this pull request as ready for review March 28, 2026 16:50
Copilot AI review requested due to automatic review settings March 28, 2026 16:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a TypeScript 6.0 regression where module-level narrowing from a broader-typed const could leak into class property initializer inference, by restoring an isolated control-flow scope for property initializers in the binder.

Changes:

  • Restore SyntaxKind.PropertyDeclaration as a control-flow container (when it has an initializer) in getContainerFlags.
  • Add a compiler regression test ensuring class/static properties infer the declared wider type (AB) rather than a narrowed literal.
  • Add new baselines (.types, .symbols, .js) for the regression test.

Reviewed changes

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

Show a summary per file
File Description
src/compiler/binder.ts Restores property declarations with initializers as isolated control-flow containers to prevent narrowing leakage into inference.
tests/cases/compiler/classPropertyInferenceFromBroaderTypeConst.ts New regression test covering instance and static class property inference from a broader-typed const.
tests/baselines/reference/classPropertyInferenceFromBroaderTypeConst.types Baseline verifying inferred types (e.g., D: AB, SD: AB) and switch narrowing behavior.
tests/baselines/reference/classPropertyInferenceFromBroaderTypeConst.symbols Baseline verifying symbol binding for the new test.
tests/baselines/reference/classPropertyInferenceFromBroaderTypeConst.js Baseline verifying emit output for the new test.

Comment on lines +3872 to +3874
case SyntaxKind.PropertyDeclaration:
return (node as PropertyDeclaration).initializer ? ContainerFlags.IsControlFlowContainer : ContainerFlags.None;

Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

PR description indicates the full test suite hasn’t been run yet. Please run the repo’s required verification (at least npx hereby runtests-parallel, plus npx hereby lint and npx hereby format if applicable) and update the PR before this is merged, since binder control-flow container changes can have broad impact.

Copilot uses AI. Check for mistakes.
@typescript-bot
Copy link
Copy Markdown
Collaborator

@RyanCavanaugh Here are the results of running the top 400 repos with tsc comparing main and refs/pull/63310/merge:

Everything looks good!

@typescript-bot
Copy link
Copy Markdown
Collaborator

@RyanCavanaugh
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - node (v18.15.0, x64)
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 82,521 82,521 ~ ~ ~ p=1.000 n=6
Types 125,280 125,280 ~ ~ ~ p=1.000 n=6
Memory used 275,005k (± 0.50%) 276,127k (± 0.68%) ~ 274,392k 277,890k p=0.936 n=6
Parse Time 1.31s (± 0.79%) 1.31s (± 0.80%) ~ 1.29s 1.32s p=0.801 n=6
Bind Time 0.76s 0.76s (± 0.54%) ~ 0.75s 0.76s p=0.405 n=6
Check Time 14.28s (± 1.15%) 14.19s (± 0.49%) ~ 14.10s 14.26s p=0.336 n=6
Emit Time 2.69s (± 0.61%) 2.69s (± 0.61%) ~ 2.67s 2.72s p=0.370 n=6
Total Time 19.04s (± 0.91%) 18.94s (± 0.43%) ~ 18.83s 19.02s p=0.296 n=6
angular-1 - node (v18.15.0, x64)
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 959,140 959,140 ~ ~ ~ p=1.000 n=6
Types 416,033 416,033 ~ ~ ~ p=1.000 n=6
Memory used 1,261,053k (± 0.01%) 1,261,321k (± 0.00%) +268k (+ 0.02%) 1,261,239k 1,261,396k p=0.005 n=6
Parse Time 8.01s (± 1.05%) 8.05s (± 0.85%) ~ 7.98s 8.16s p=0.520 n=6
Bind Time 2.40s (± 0.82%) 2.39s (± 1.10%) ~ 2.35s 2.42s p=0.359 n=6
Check Time 38.81s (± 0.42%) 38.72s (± 0.53%) ~ 38.49s 38.96s p=0.470 n=6
Emit Time 18.11s (± 0.48%) 18.08s (± 0.65%) ~ 17.85s 18.18s p=0.689 n=6
Total Time 67.33s (± 0.29%) 67.23s (± 0.40%) ~ 67.02s 67.63s p=0.689 n=6
mui-docs - node (v18.15.0, x64)
Errors 11,136 11,136 ~ ~ ~ p=1.000 n=6
Symbols 2,202,148 2,202,148 ~ ~ ~ p=1.000 n=6
Types 764,674 764,674 ~ ~ ~ p=1.000 n=6
Memory used 2,642,677k (± 0.00%) 2,642,601k (± 0.00%) ~ 2,642,416k 2,642,791k p=0.298 n=6
Parse Time 9.52s (± 0.25%) 9.52s (± 0.18%) ~ 9.49s 9.54s p=1.000 n=6
Bind Time 2.50s (± 1.40%) 2.53s (± 0.63%) ~ 2.51s 2.55s p=0.256 n=6
Check Time 86.29s (± 1.63%) 87.59s (± 2.03%) ~ 85.49s 90.33s p=0.298 n=6
Emit Time 0.36s (± 2.48%) 0.37s (± 3.17%) ~ 0.35s 0.38s p=0.214 n=6
Total Time 98.68s (± 1.41%) 100.01s (± 1.78%) ~ 97.92s 102.78s p=0.173 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,227,363 1,227,363 ~ ~ ~ p=1.000 n=6
Types 267,197 267,198 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,779,598k (± 9.86%) 2,779,994k (± 5.35%) ~ 2,718,790k 3,083,850k p=0.378 n=6
Parse Time 6.58s (± 1.21%) 6.55s (± 0.81%) ~ 6.51s 6.65s p=0.689 n=6
Bind Time 2.24s (± 1.18%) 2.24s (± 0.68%) ~ 2.21s 2.25s p=0.872 n=6
Check Time 43.09s (± 0.51%) 42.85s (± 0.83%) ~ 42.41s 43.40s p=0.173 n=6
Emit Time 3.56s (± 2.90%) 3.59s (± 3.14%) ~ 3.48s 3.76s p=0.873 n=6
Total Time 55.48s (± 0.55%) 55.22s (± 0.75%) ~ 54.69s 55.73s p=0.575 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,227,363 1,227,363 ~ ~ ~ p=1.000 n=6
Types 267,197 267,198 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,785,493k (± 8.21%) 2,785,042k (± 0.02%) ~ 2,784,403k 2,785,587k p=1.000 n=6
Parse Time 6.73s (± 1.23%) 6.69s (± 0.73%) ~ 6.63s 6.75s p=0.689 n=6
Bind Time 2.23s (± 0.52%) 2.26s (± 1.74%) ~ 2.22s 2.32s p=0.127 n=6
Check Time 43.00s (± 0.85%) 42.82s (± 0.55%) ~ 42.52s 43.22s p=0.298 n=6
Emit Time 3.52s (± 4.16%) 3.58s (± 5.07%) ~ 3.41s 3.88s p=0.521 n=6
Total Time 55.52s (± 0.69%) 55.35s (± 0.75%) ~ 54.85s 55.91s p=0.575 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 261,660 261,660 ~ ~ ~ p=1.000 n=6
Types 104,322 104,323 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 439,336k (± 0.01%) 439,347k (± 0.01%) ~ 439,248k 439,402k p=0.630 n=6
Parse Time 3.52s (± 0.72%) 3.52s (± 0.54%) ~ 3.49s 3.54s p=0.933 n=6
Bind Time 1.34s (± 1.05%) 1.38s (± 1.33%) +0.04s (+ 2.86%) 1.36s 1.40s p=0.008 n=6
Check Time 19.32s (± 0.48%) 19.30s (± 0.39%) ~ 19.21s 19.39s p=0.689 n=6
Emit Time 1.55s (± 1.49%) 1.56s (± 0.94%) ~ 1.54s 1.58s p=0.869 n=6
Total Time 25.74s (± 0.28%) 25.76s (± 0.35%) ~ 25.63s 25.88s p=0.688 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 271 271 ~ ~ ~ p=1.000 n=6
Symbols 225,897 225,897 ~ ~ ~ p=1.000 n=6
Types 93,564 93,564 ~ ~ ~ p=1.000 n=6
Memory used 371,594k (± 0.01%) 371,632k (± 0.02%) ~ 371,573k 371,807k p=0.471 n=6
Parse Time 2.85s (± 0.79%) 2.85s (± 0.60%) ~ 2.83s 2.87s p=0.807 n=6
Bind Time 1.64s (± 0.99%) 1.64s (± 0.71%) ~ 1.62s 1.65s p=0.568 n=6
Check Time 17.46s (± 0.22%) 17.44s (± 0.50%) ~ 17.29s 17.53s p=0.685 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 21.95s (± 0.26%) 21.94s (± 0.43%) ~ 21.77s 22.01s p=0.686 n=6
vscode - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=NaN n=0
Symbols 0 0 ~ ~ ~ p=NaN n=0
Types 0 0 ~ ~ ~ p=NaN n=0
Memory used 0k 0k ~ ~ ~ p=NaN n=0
Parse Time 0s 0s ~ ~ ~ p=NaN n=0
Bind Time 0s 0s ~ ~ ~ p=NaN n=0
Check Time 0s 0s ~ ~ ~ p=NaN n=0
Emit Time 0s 0s ~ ~ ~ p=NaN n=0
Total Time 0s 0s ~ ~ ~ p=NaN n=0
webpack - node (v18.15.0, x64)
Errors 8 8 ~ ~ ~ p=1.000 n=6
Symbols 408,835 408,835 ~ ~ ~ p=1.000 n=6
Types 186,908 186,908 ~ ~ ~ p=1.000 n=6
Memory used 570,889k (± 0.02%) 570,961k (± 0.02%) ~ 570,797k 571,065k p=0.298 n=6
Parse Time 4.75s (± 0.64%) 4.73s (± 0.84%) ~ 4.66s 4.78s p=0.517 n=6
Bind Time 2.02s (± 0.88%) 2.05s (± 1.62%) ~ 2.00s 2.09s p=0.063 n=6
Check Time 24.48s (± 0.42%) 24.47s (± 0.54%) ~ 24.29s 24.62s p=0.873 n=6
Emit Time 0.00s (±154.76%) 0.01s (±77.38%) ~ 0.00s 0.01s p=0.311 n=6
Total Time 31.25s (± 0.41%) 31.25s (± 0.58%) ~ 30.99s 31.49s p=1.000 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 781,066 781,066 ~ ~ ~ p=1.000 n=6
Types 227,795 227,795 ~ ~ ~ p=1.000 n=6
Memory used 697,180k (± 0.01%) 697,166k (± 0.01%) ~ 697,097k 697,250k p=0.575 n=6
Parse Time 3.98s (± 0.44%) 3.98s (± 0.63%) ~ 3.95s 4.01s p=1.000 n=6
Bind Time 1.34s (± 0.47%) 1.35s (± 0.56%) ~ 1.34s 1.36s p=0.081 n=6
Check Time 19.37s (± 0.45%) 19.43s (± 0.46%) ~ 19.33s 19.53s p=0.261 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 24.68s (± 0.41%) 24.75s (± 0.34%) ~ 24.64s 24.85s p=0.228 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in 6.0: type inferred from const with broader type is too narrow

5 participants