Skip to content

fix(compiler-cli): re-tag SourceFiles after TsCreateProgramDriver.updateFiles()#69548

Open
LordKay-sudo wants to merge 1 commit into
angular:mainfrom
LordKay-sudo:fix/ts-create-program-driver-retag
Open

fix(compiler-cli): re-tag SourceFiles after TsCreateProgramDriver.updateFiles()#69548
LordKay-sudo wants to merge 1 commit into
angular:mainfrom
LordKay-sudo:fix/ts-create-program-driver-retag

Conversation

@LordKay-sudo

Copy link
Copy Markdown

Summary

  • Re-apply retagAllTsFiles(this.program) after untagAllTsFiles(oldProgram) in TsCreateProgramDriver.updateFiles().
  • TypeScript reuses SourceFile objects between old and new programs, so untagging the old program also untags shared files in the new program. Without re-tagging, getSemanticDiagnostics() can crash on TS 5.9+ with Cannot destructure property 'pos' of 'file.referencedFiles[index]'.
  • Adds a regression test asserting shim tags are retained on shared SourceFiles after updateFiles().

Fixes #68164

Test plan

  • Reproduced locally: without the fix, referencedFiles.length drops below taggedReferenceFiles.length after updateFiles() (shared SourceFile untagged).
  • With the fix, referencedFiles matches taggedReferenceFiles and getSemanticDiagnostics() completes without throwing.
  • bazel test //packages/compiler-cli/src/ngtsc/typecheck/test:test (could not run Bazel locally on Windows due to bash genrule failure; CI should validate)

@pullapprove pullapprove Bot requested a review from kirjs June 27, 2026 13:34
@google-cla

google-cla Bot commented Jun 27, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Jun 27, 2026
@ngbot ngbot Bot added this to the Backlog milestone Jun 27, 2026
@LordKay-sudo LordKay-sudo force-pushed the fix/ts-create-program-driver-retag branch from f36d951 to 7c17dc5 Compare June 27, 2026 14:20
@JeanMeche JeanMeche requested a review from JoostK June 29, 2026 12:24
@LordKay-sudo

Copy link
Copy Markdown
Author

CI was failing because the test imported \isExtended\ from ../../shims, but that symbol isn't part of the public shims API. Dropped the import in 9e96059. The test still checks that
eferencedFiles\ matches \ aggedReferenceFiles\ after \updateFiles().

@LordKay-sudo LordKay-sudo force-pushed the fix/ts-create-program-driver-retag branch from 9e96059 to f889376 Compare July 1, 2026 10:15

@JoostK JoostK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just noting here that I'm aware of this PR; it's just that I need to look into this proper; I'm not certain that tagging the main TS program won't introduce problems w.r.t dangling .ngtypecheck.ts references in the program that's used for emit.

@LordKay-sudo

LordKay-sudo commented Jul 2, 2026

Copy link
Copy Markdown
Author

Thanks for looking at this, @JoostK . Fair point on the emit side.

The retagAllTsFiles(this.program) call only restores taggedReferenceFiles that were already recorded during createProgram. It doesn't add new shim references.

Emit still goes through this.tsProgram, and prepareEmit() calls untagAllTsFiles(this.inputProgram) before emit (#56945 / #57135). So the typecheck program can stay tagged for diagnostics without those refs leaking into emit.

Pushed two follow-up tests in d8927ca:

  • incremental updateFiles() diagnostics (UpdateMode.Incremental)
  • emit path: shared input program files are untagged (no .ngtypecheck.ts refs) after untagAllTsFiles, matching what prepareEmit() does

@JoostK JoostK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the update. There's a few remaining problems:

  1. The tests do not compile; fixing that reveals a failing test.
  2. When uncommenting the length assertions to allow the getSemanticDiagnostics check to be exercised, no tests fail after uncommenting the fix.

Please also squash all commits into a single fix commit, or use fixup! commits if you want to retain the commit fidelity in the PR (will be autosquashed when merged)

…ateFiles()

TypeScript reuses SourceFile objects between old and new programs, so untagging the old program also untags shared files in the new program. Re-apply shim tags on the new program to prevent getSemanticDiagnostics() crashes with TS 5.5+.

Adds regression tests that update shim files only so shared SourceFiles remain shared, and verifies both diagnostic safety and emit-time untagging.

Fixes angular#68164
@LordKay-sudo LordKay-sudo force-pushed the fix/ts-create-program-driver-retag branch from d8927ca to 9d67100 Compare July 6, 2026 05:20
@LordKay-sudo

Copy link
Copy Markdown
Author

@JoostK Thanks for the review. Pushed a squashed fix in 9d67100.

On the tests:

  1. The compile issue was comparing against a possibly-null originalReferencedFiles; fixed with an explicit null check and toEqual.
  2. The tests were updating /main.ts, which replaces the SourceFile in the typecheck program rather than reusing it. They now update only the shim file so /main.ts stays shared between programs, which is the scenario the fix targets.
  3. Added composite + declaration compiler options so getSemanticDiagnostics() actually exercises the fileProcessingDiagnostics path from the bug report.

The length assertion and getSemanticDiagnostics() check should now fail if retagAllTsFiles(this.program) is removed.

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

Labels

area: compiler Issues related to `ngc`, Angular's template compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TsCreateProgramDriver.updateFiles() untags shared SourceFiles, crashing getSemanticDiagnostics() with TS 5.9

2 participants