Fixed (Critical null pointer bug) in incremental builder #61807
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR addresses a critical null pointer issue in TypeScript's incremental compilation builder system and fixes property mapping inconsistencies in diagnostic conversion functions.
Issues Fixed
1. Critical Null Pointer Bug in Builder System
src/compiler/builder.ts
lines 643 and 2147state.affectedFilesIndex
was accessed with non-null assertion (!
) despite being defined asnumber | undefined
in theBuilderProgramState
interfaceaffectedFilesIndex
is undefined during incremental builds??
)2. Diagnostic Property Mapping Inconsistencies
src/compiler/builder.ts
lines 577 and 1507Diagnostic
andReusableDiagnostic
types:Diagnostic
hasreportsDeprecated
propertyReusableDiagnostic
hasreportDeprecated
propertyconvertToDiagnostics
:diagnostic.reportDeprecated
→result.reportsDeprecated
toReusableDiagnostic
:diagnostic.reportsDeprecated
→result.reportDeprecated
Technical Details
The
affectedFilesIndex
tracks the current position when iterating through files affected by changes in incremental compilation. The interface correctly allows this to beundefined
, but the implementation incorrectly assumed it was always defined.This bug could manifest during:
Code Changes
Risk Assessment
Low Risk: Changes only affect error-prone undefined access patterns and incorrect property mappings. The fixes make the code more robust and type-safe without changing core functionality.
Consideration
The following line
644
Was commented as
TODO: GH#18217
Testing Notes
hereby runtests
) should be run to ensure no regressions