Fix signature help crash when nested call has trailing comma
- [x] Understand the issue: crash in
getArgumentArityErrorwhenmaxCount >= len(args) - [x] Identify root cause: accessing
args[maxCount]without bounds check in the default branch - [x] Update test to use minimal repro with correct marker position and trigger kind
- [x] Verify test reproduces the crash without the fix
- [x] Implement the fix in
checker.go- add bounds check before accessingargs[maxCount] - [x] Verify the fix works and all tests pass
- [x] Run linting and formatting
Original prompt
This section details on the original issue you should resolve
<issue_title>Signature help crash on call target when nested call has trailing comma</issue_title> <issue_description>Had a hard time coming up with a minimal repro but here's the actual code it was found in.
https://github.com/microsoft/TypeScript/blob/1da8266179589bbc977ccbd8712614ed5ddd3004/src/services/navigationBar.ts#L681-L690
factory.createClassDeclaration/**/(
If you request signature help at the marker very quickly, you can trigger the following crash. This is tricky because it doesn't always happen. One way to often accomplish this in VS Code is to
- Trigger signature help (Ctrl+Shift+Space or just type
,and delete it) - Insert a stray character at the marker
- Immediately delete that stray character
error] panic handling requesttextDocument/signatureHelpruntime error: index out of range [5] with length 5goroutine 52857 [running]:
runtime/debug.Stack()
runtime/debug/stack.go:26 +0x5e
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0xc0001e4008, 0xc047ef9620)
github.com/microsoft/typescript-go/internal/lsp/server.go:701 +0x58
panic({0xca4c60?, 0xc039fbedb0?})
runtime/panic.go:783 +0x132
github.com/microsoft/typescript-go/internal/checker.(*Checker).getArgumentArityError(0xc04bddf308, 0xc04b108088, {0xc04bda8cc8, 0x1, 0xc001964c58?}, {0xc0544361a8, 0x5, 0x5?}, 0x0)
github.com/microsoft/typescript-go/internal/checker/checker.go:9652 +0xa96
github.com/microsoft/typescript-go/internal/checker.(*Checker).reportCallResolutionErrors(0xc04bddf308, 0x109c2c0?, 0xc001964cf0, {0xc04bda8cc8, 0x1, 0x1}, 0x0)
github.com/microsoft/typescript-go/internal/checker/checker.go:9540 +0x1f2
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveCall(0xc04bddf308, 0xc04b108088, {0xc04bda8cc8, 0x1, 0x1}, 0x0, 0x1f, 0x0, 0x0)
github.com/microsoft/typescript-go/internal/checker/checker.go:8778 +0x605
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveCallExpression(0xc04bddf308, 0xc04b108088, 0x0, 0x1f)
github.com/microsoft/typescript-go/internal/checker/checker.go:8405 +0x62d
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveSignature(0xc04bddfa60?, 0x109c2c0?, 0xc04b108088?, 0x85688e?)
github.com/microsoft/typescript-go/internal/checker/checker.go:8292 +0x46
github.com/microsoft/typescript-go/internal/checker.(*Checker).getResolvedSignature(0xc04bddf308, 0xc04b108088, 0x0, 0x1f)
github.com/microsoft/typescript-go/internal/checker/checker.go:8264 +0xd8
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkCallExpression(0xc04bddf308, 0xc04b108088, 0x1f)
github.com/microsoft/typescript-go/internal/checker/checker.go:8160 +0x4f
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkExpressionWorker(0xc04bddf308, 0xc04b108088, 0x1f)
github.com/microsoft/typescript-go/internal/checker/checker.go:7546 +0x2df
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkExpressionEx(0xc04bddf308, 0xc04b108088, 0x1f)
github.com/microsoft/typescript-go/internal/checker/checker.go:7334 +0x52
github.com/microsoft/typescript-go/internal/checker.(*Checker).checkExpressionWithContextualType(0xc04bddf308, 0xc04bdac900?, 0xc04cf1a770, 0xc04bdac700, 0x1c)
github.com/microsoft/typescript-go/internal/checker/checker.go:7261 +0x22c
github.com/microsoft/typescript-go/internal/checker.(*Checker).inferTypeArguments(0xc04bddf308, 0xc04b1080e0, 0xc01cdfa100, {0xc0544361d0, 0x2, 0x2}, 0x1c, 0xc04bdac700)
github.com/microsoft/typescript-go/internal/checker/checker.go:9345 +0x41e
github.com/microsoft/typescript-go/internal/checker.(*Checker).inferSignatureInstantiationForOverloadFailure(0xc04bddf308, 0xc04b1080e0, {0xc04bda8b48?, 0x3?, 0x781bb5?}, 0xc01cdfa100, {0xc0544361d0, 0x2, 0x2}, 0x10)
github.com/microsoft/typescript-go/internal/checker/checker.go:9437 +0x93
github.com/microsoft/typescript-go/internal/checker.(*Checker).pickLongestCandidateSignature(0xc04bddf308, 0xc04b1080e0, {0xc04bda8b58, 0x1, 0xc04bda8b58?}, {0xc0544361d0, 0x2, 0x2}, 0x10)
github.com/microsoft/typescript-go/internal/checker/checker.go:9395 +0x1d6
github.com/microsoft/typescript-go/internal/checker.(*Checker).getCandidateForOverloadFailure(0xc04bddf308, 0xc04b1080e0, {0xc04bda8b58, 0x1, 0x1}, {0xc0544361d0, 0x2, 0x2}, 0x1, 0x10)
github.com/microsoft/typescript-go/internal/checker/checker.go:9365 +0xb4
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveCall(0xc04bddf308, 0xc04b1080e0, {0xc04bda8b50, 0x1, 0x1}, 0xc0019654f8, 0x10, 0x0, 0x0)
github.com/microsoft/typescript-go/internal/checker/checker.go:8758 +0x53d
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveCallExpression(0xc04bddf308, 0xc04b1080e0, 0xc0019654f8, 0x10)
github.com/microsoft/typescript-go/internal/checker/checker.go:8405 +0x62d
github.com/microsoft/typescript-go/internal/checker.(*Checker).resolveSignature(0xc04bd...
</details>
<!-- START COPILOT CODING AGENT SUFFIX -->
- Fixes microsoft/typescript-go#2312
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.
Try again @copilot.
Fixed the test to use the minimal repro with the correct marker position. The test now properly reproduces the crash (index out of range [1] with length 1) without the fix. (0d98c09f)