Skip to content

Implement pre-emit/post-emit diagnostic count mismatch detection (TS-1)#3738

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/fix-ts-1-diagnostic-emission
Draft

Implement pre-emit/post-emit diagnostic count mismatch detection (TS-1)#3738
Copilot wants to merge 5 commits intomainfrom
copilot/fix-ts-1-diagnostic-emission

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 7, 2026

The test harness was missing the TS-1 internal diagnostic that detects when emit causes the checker to discover new semantic errors via the emit resolver. This was stubbed out with comments referencing the TypeScript implementation but never ported.

Changes

  • internal/diagnostics/diagnostics.go — Add NewMessage() constructor for creating Message objects with arbitrary code/category/text, needed for the synthetic TS-1 diagnostics
  • internal/testutil/harnessutil/harnessutil.go — Replace commented-out comparison logic with working implementation:
    • Collect diagnostic counts (program + syntactic + semantic + global) before emit
    • Emit, then re-collect the same diagnostics after emit
    • If counts differ, use the shorter list as the base result and append a TS-1 mismatch diagnostic with excess diagnostics as related info
    • Declaration diagnostics are excluded from the comparison to avoid false positives from GetDeclarationDiagnostics triggering the emit resolver as a side effect (Go shares checker state within a single program, unlike TS which uses two independent programs)
    • Skip comparison for large test suites (≥100 files) or when skipLibCheck && declaration are both set
  • Baselines — The three target .diff files are removed (output now matches TypeScript reference), and their entries are removed from submoduleTriaged.txt

Example output

error TS-1: Pre-emit (1) and post-emit (5) diagnostic counts do not match! This can indicate that a semantic _error_ was added by the emit resolver - such an error may not be reflected on the command line or in the editor, but may be captured in a baseline here!
!!! related TS-1: The excess diagnostics are:
!!! related TS2304 file.ts:1:18: Cannot find name 'role'.

Uncomment and implement the pre-emit/post-emit diagnostic comparison
in the test harness. This creates a separate pre-program to collect
diagnostics before emit, then compares with post-emit diagnostics
from the main program. When counts differ, a TS-1 internal diagnostic
is emitted with details about the excess diagnostics.

Also adds diagnostics.NewMessage() to create custom Message objects
for the TS-1 diagnostics, and resets the tracer between pre and main
programs to avoid trace pollution.

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/1afca828-e811-4d01-9523-d815fcf522d1

Co-authored-by: gabritto <19519347+gabritto@users.noreply.github.com>
Comment thread internal/diagnostics/diagnostics.go
@jakebailey
Copy link
Copy Markdown
Member

I think this is technically a dupe of #1301 but it's been a while so I think we don't need some of the fixes in that PR?

Copilot AI and others added 2 commits May 7, 2026 19:09
…arison

Use a single program to collect diagnostics before and after emit,
comparing counts excluding declaration diagnostics to avoid
GetDeclarationDiagnostics side-effect pollution. When counts differ,
use the shorter diagnostic list as the base result (matching TS behavior).

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/1afca828-e811-4d01-9523-d815fcf522d1

Co-authored-by: gabritto <19519347+gabritto@users.noreply.github.com>
Only keep baseline changes for the three target tests specified
in the issue. Remove all other baseline changes that were
accidentally included from a full test run baseline-accept.

Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/1afca828-e811-4d01-9523-d815fcf522d1

Co-authored-by: gabritto <19519347+gabritto@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Corsa diagnostics for pre-emit and post-emit mismatches Implement pre-emit/post-emit diagnostic count mismatch detection (TS-1) May 7, 2026
Copilot AI requested a review from gabritto May 7, 2026 19:10
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.

Corsa no longer emits the TS-1 internal diagnostic about pre-emit/post-emit diagnostic count mismatches

3 participants