From 1d65ff0897afc166c3e794eb5347f0fc40347f01 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:25:19 +0000 Subject: [PATCH 1/3] Initial plan From b1fa3e5febb4193acef51f975e895eb5079a79fa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:31:24 +0000 Subject: [PATCH 2/3] Assert checker errors do not use the Message diagnostic category Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com> --- tsc/internal/checker/checker.go | 1 + tsc/internal/checker/diagnostics_test.go | 35 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tsc/internal/checker/diagnostics_test.go diff --git a/tsc/internal/checker/checker.go b/tsc/internal/checker/checker.go index 80a2afdf5d6b7..0c117798b2df9 100644 --- a/tsc/internal/checker/checker.go +++ b/tsc/internal/checker/checker.go @@ -14277,6 +14277,7 @@ func (c *Checker) produceDeferredDiagnostics() { } func (c *Checker) addDiagnostic(diagnostic *ast.Diagnostic) *ast.Diagnostic { + debug.Assert(diagnostic.Category() != diagnostics.CategoryMessage, "Cannot report a Message-category diagnostic as an error.") // Discard diagnostics created while at the maximum number of recursive TypeToString invocations. if c.serializationLevel < maxSerializationLevel { return c.diagnostics.Add(diagnostic) diff --git a/tsc/internal/checker/diagnostics_test.go b/tsc/internal/checker/diagnostics_test.go new file mode 100644 index 0000000000000..c154f3a9aeac9 --- /dev/null +++ b/tsc/internal/checker/diagnostics_test.go @@ -0,0 +1,35 @@ +package checker + +import ( + "testing" + + "github.com/microsoft/TypeScript/tsc/internal/ast" + "github.com/microsoft/TypeScript/tsc/internal/diagnostics" + "gotest.tools/v3/assert" +) + +func TestAddDiagnosticRejectsMessageCategory(t *testing.T) { + t.Parallel() + + c := &Checker{} + diagnostic := ast.NewCompilerDiagnostic(diagnostics.File_is_included_via_import_here) + defer func() { + assert.Equal(t, recover(), "Debug failure. False expression: Cannot report a Message-category diagnostic as an error.") + assert.Equal(t, len(c.diagnostics.GetDiagnostics()), 0) + }() + c.addDiagnostic(diagnostic) +} + +func TestAddDiagnosticAllowsMessageRelatedInformation(t *testing.T) { + t.Parallel() + + c := &Checker{} + related := ast.NewCompilerDiagnostic(diagnostics.File_is_included_via_import_here) + diagnostic := ast.NewCompilerDiagnostic(diagnostics.Cannot_find_name_0, "x").AddRelatedInfo(related) + + assert.Equal(t, c.addDiagnostic(diagnostic), diagnostic) + collected := c.diagnostics.GetDiagnostics() + assert.Equal(t, len(collected), 1) + assert.Equal(t, collected[0], diagnostic) + assert.Equal(t, diagnostic.RelatedInformation()[0].Category(), diagnostics.CategoryMessage) +} From 3570fb409fa4161b61c9e9175ff84889fc85de3b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 5 Nov 2026 17:47:59 +0000 Subject: [PATCH 3/3] Remove diagnostic assertion tests per review Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com> --- tsc/internal/checker/diagnostics_test.go | 35 ------------------------ 1 file changed, 35 deletions(-) delete mode 100644 tsc/internal/checker/diagnostics_test.go diff --git a/tsc/internal/checker/diagnostics_test.go b/tsc/internal/checker/diagnostics_test.go deleted file mode 100644 index c154f3a9aeac9..0000000000000 --- a/tsc/internal/checker/diagnostics_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package checker - -import ( - "testing" - - "github.com/microsoft/TypeScript/tsc/internal/ast" - "github.com/microsoft/TypeScript/tsc/internal/diagnostics" - "gotest.tools/v3/assert" -) - -func TestAddDiagnosticRejectsMessageCategory(t *testing.T) { - t.Parallel() - - c := &Checker{} - diagnostic := ast.NewCompilerDiagnostic(diagnostics.File_is_included_via_import_here) - defer func() { - assert.Equal(t, recover(), "Debug failure. False expression: Cannot report a Message-category diagnostic as an error.") - assert.Equal(t, len(c.diagnostics.GetDiagnostics()), 0) - }() - c.addDiagnostic(diagnostic) -} - -func TestAddDiagnosticAllowsMessageRelatedInformation(t *testing.T) { - t.Parallel() - - c := &Checker{} - related := ast.NewCompilerDiagnostic(diagnostics.File_is_included_via_import_here) - diagnostic := ast.NewCompilerDiagnostic(diagnostics.Cannot_find_name_0, "x").AddRelatedInfo(related) - - assert.Equal(t, c.addDiagnostic(diagnostic), diagnostic) - collected := c.diagnostics.GetDiagnostics() - assert.Equal(t, len(collected), 1) - assert.Equal(t, collected[0], diagnostic) - assert.Equal(t, diagnostic.RelatedInformation()[0].Category(), diagnostics.CategoryMessage) -}