Skip to content

Commit 41455a6

Browse files
Fix signature help crash when nested call has trailing comma (#2315)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: DanielRosenwasser <[email protected]>
1 parent 5ac8497 commit 41455a6

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

internal/checker/checker.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9638,6 +9638,17 @@ func (c *Checker) getArgumentArityError(node *ast.Node, signatures []*Signature,
96389638
}
96399639
return diagnostic
96409640
default:
9641+
// Guard against out-of-bounds access when maxCount >= len(args).
9642+
// This can happen when we reach this fallback error path but the argument
9643+
// count actually matches the parameter count (e.g., due to trailing commas
9644+
// causing signature resolution to fail for other reasons).
9645+
if maxCount >= len(args) {
9646+
diagnostic := NewDiagnosticForNode(errorNode, message, parameterRange, len(args))
9647+
if headMessage != nil {
9648+
diagnostic = ast.NewDiagnosticChain(diagnostic, headMessage)
9649+
}
9650+
return diagnostic
9651+
}
96419652
sourceFile := ast.GetSourceFileOfNode(node)
96429653
pos := scanner.SkipTrivia(sourceFile.Text(), args[maxCount].Pos())
96439654
end := args[len(args)-1].End()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
8+
"github.com/microsoft/typescript-go/internal/testutil"
9+
)
10+
11+
func TestSignatureHelpNestedCallTrailingComma(t *testing.T) {
12+
t.Parallel()
13+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
14+
// Regression test for crash when requesting signature help on a call target
15+
// where the nested call has a trailing comma.
16+
// Both outer and inner calls must have trailing commas, and outer must be generic.
17+
const content = `declare function outer<T>(range: T): T;
18+
declare function inner(a: any): any;
19+
20+
outer(inner/*1*/(undefined,),);`
21+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
22+
defer done()
23+
f.GoToMarker(t, "1")
24+
f.VerifySignatureHelpPresent(t, &lsproto.SignatureHelpContext{
25+
IsRetrigger: false,
26+
TriggerKind: lsproto.SignatureHelpTriggerKindInvoked,
27+
})
28+
}

0 commit comments

Comments
 (0)