Skip to content

Add regression test for inlay hints crash on reparsed nodes (#2460)#2908

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-regression-test-inlay-hints-crash
Draft

Add regression test for inlay hints crash on reparsed nodes (#2460)#2908
Copilot wants to merge 2 commits intomainfrom
copilot/add-regression-test-inlay-hints-crash

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

Regression test for the panic when computing inlay hints on a JS file using module.exports = function() {...}, which produces reparsed AST nodes. The fix (checking node.Flags&ast.NodeFlagsReparsed != 0 in inlay_hints.go) was applied in #2593; this test ensures it doesn't regress.

Changes

  • internal/fourslash/tests/inlayHintsReparsedNodeCrash_test.go — fourslash test exercising inlay hints on a CommonJS module.exports function with return type and parameter hints enabled
  • testdata/baselines/reference/fourslash/inlayHints/inlayHintsReparsedNodeCrash.baseline — expected baseline: : number return type hint on the anonymous function
// @allowJs: true
// @checkJs: true
module.exports = function () {
  return 1;
};
// inlay hint → `: number` return type
Original prompt

Add a regression test for the inlay hints crash reported in #2460, using the minimal reproduction from #2460 (comment).

The fix was applied in PR #2593, which added a check for node.Flags&ast.NodeFlagsReparsed != 0 in the visit method of internal/ls/inlay_hints.go. This test should verify that the fix works and would fail/panic without it.

What to do

Create a new test file at internal/fourslash/tests/inlayHintsReparsedNodeCrash_test.go with the following content:

package fourslash_test

import (
	"testing"

	"github.com/microsoft/typescript-go/internal/fourslash"
	"github.com/microsoft/typescript-go/internal/ls/lsutil"
	"github.com/microsoft/typescript-go/internal/testutil"
)

func TestInlayHintsReparsedNodeCrash(t *testing.T) {
	t.Parallel()

	defer testutil.RecoverAndFail(t, "Panic on fourslash test")
	const content = `
// @allowJs: true
// @checkJs: true

// @Filename: /a.js
module.exports = function () {
  return 1;
};
`

	f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
	defer done()
	f.VerifyBaselineInlayHints(t, nil /*span*/, &lsutil.UserPreferences{InlayHints: lsutil.InlayHintsPreferences{
		IncludeInlayFunctionLikeReturnTypeHints: true,
		IncludeInlayFunctionParameterTypeHints:  true,
	}})
}

This follows the same patterns as other manually-written inlay hints tests in internal/fourslash/tests/ such as inlayHintsTupleTypeCrash_test.go and inlayHintsUsing_test.go.

Also generate/update the corresponding baseline file. Run the test to make sure it passes. The test exercises inlay hints on a JavaScript file using module.exports = function() { ... } which involves reparsed nodes. Without the fix from PR #2593, this would panic.

Verification

Confirm the test passes with the current code (which includes the fix from #2593). The key fix is in internal/ls/inlay_hints.go at line 63:

func (s *inlayHintState) visit(node *ast.Node) bool {
	if node == nil || node.End()-node.Pos() == 0 || node.Flags&ast.NodeFlagsReparsed != 0 {
		return false
	}

Without the node.Flags&ast.NodeFlagsReparsed != 0 check, the test would crash/panic when processing inlay hints on the reparsed nodes from the CommonJS module.exports pattern.

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add regression test for inlay hints crash Add regression test for inlay hints crash on reparsed nodes (#2460) Feb 26, 2026
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.

2 participants