Skip to content

Commit 0d98c09

Browse files
Fix signature help crash with trailing comma and update test with minimal repro
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
1 parent a453037 commit 0d98c09

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

internal/checker/checker.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9648,9 +9648,10 @@ func (c *Checker) getArgumentArityError(node *ast.Node, signatures []*Signature,
96489648
}
96499649
return diagnostic
96509650
default:
9651-
// Handle edge case where maxCount >= len(args)
9652-
// This can happen when signature resolution fails for reasons other than argument count,
9653-
// such as when trailing commas create OmittedExpressions that affect type inference.
9651+
// Guard against out-of-bounds access when maxCount >= len(args).
9652+
// This can happen when we reach this fallback error path but the argument
9653+
// count actually matches the parameter count (e.g., due to trailing commas
9654+
// causing signature resolution to fail for other reasons).
96549655
if maxCount >= len(args) {
96559656
diagnostic := NewDiagnosticForNode(errorNode, message, parameterRange, len(args))
96569657
if headMessage != nil {

internal/fourslash/tests/signatureHelpNestedCallTrailingComma_test.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"testing"
55

66
"github.com/microsoft/typescript-go/internal/fourslash"
7-
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
87
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
98
"github.com/microsoft/typescript-go/internal/testutil"
109
)
@@ -16,23 +15,14 @@ func TestSignatureHelpNestedCallTrailingComma(t *testing.T) {
1615
// where the nested call has a trailing comma.
1716
// Both outer and inner calls must have trailing commas, and outer must be generic.
1817
const content = `declare function outer<T>(range: T): T;
19-
declare function inner(a: any, b: any, c: any, d: any, e: any): any;
18+
declare function inner(a: any): any;
2019
21-
outer(
22-
inner(/*1*/
23-
undefined,
24-
undefined,
25-
undefined,
26-
undefined,
27-
undefined,
28-
),
29-
);`
20+
outer(inner/*1*/(undefined,),);`
3021
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
3122
defer done()
3223
f.GoToMarker(t, "1")
3324
f.VerifySignatureHelpPresent(t, &lsproto.SignatureHelpContext{
34-
IsRetrigger: false,
35-
TriggerCharacter: PtrTo("("),
36-
TriggerKind: lsproto.SignatureHelpTriggerKindTriggerCharacter,
25+
IsRetrigger: false,
26+
TriggerKind: lsproto.SignatureHelpTriggerKindInvoked,
3727
})
3828
}

0 commit comments

Comments
 (0)