Skip to content

Commit 37a839f

Browse files
committed
Merge pull request #848 from Microsoft/sigHelpCrash
Add asserts to help diagnose signature help crash #832
2 parents 39bcb10 + 0cb9972 commit 37a839f

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/compiler/parser.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,9 +2397,6 @@ module ts {
23972397
else {
23982398
parseExpected(SyntaxKind.OpenParenToken);
23992399
}
2400-
// It is an error to have a trailing comma in an argument list. However, the checker
2401-
// needs evidence of a trailing comma in order to give good results for signature help.
2402-
// That is why we do not allow a trailing comma, but we "preserve" a trailing comma.
24032400
callExpr.arguments = parseDelimitedList(ParsingContext.ArgumentExpressions,
24042401
parseArgumentExpression, /*allowTrailingComma*/ false);
24052402
parseExpected(SyntaxKind.CloseParenToken);
@@ -2627,9 +2624,6 @@ module ts {
26272624
parseExpected(SyntaxKind.NewKeyword);
26282625
node.func = parseCallAndAccess(parsePrimaryExpression(), /* inNewExpression */ true);
26292626
if (parseOptional(SyntaxKind.OpenParenToken) || token === SyntaxKind.LessThanToken && (node.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) {
2630-
// It is an error to have a trailing comma in an argument list. However, the checker
2631-
// needs evidence of a trailing comma in order to give good results for signature help.
2632-
// That is why we do not allow a trailing comma, but we "preserve" a trailing comma.
26332627
node.arguments = parseDelimitedList(ParsingContext.ArgumentExpressions,
26342628
parseArgumentExpression, /*allowTrailingComma*/ false);
26352629
parseExpected(SyntaxKind.CloseParenToken);

src/services/signatureHelp.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ module ts.SignatureHelp {
241241
return undefined;
242242
}
243243

244+
// If the node is not a subspan of its parent, this is a big problem.
245+
// There have been crashes that might be caused by this violation.
246+
if (n.pos < n.parent.pos || n.end > n.parent.end) {
247+
Debug.fail("Node of kind " + SyntaxKind[n.kind] + " is not a subspan of its parent of kind " + SyntaxKind[n.parent.kind]);
248+
}
249+
244250
var argumentInfo = getImmediatelyContainingArgumentInfo(n);
245251
if (argumentInfo) {
246252
return argumentInfo;

src/services/utilities.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ module ts {
2727
// for the position of the relevant node (or comma).
2828
var syntaxList = forEach(node.parent.getChildren(), c => {
2929
// find syntax list that covers the span of the node
30-
if (c.kind == SyntaxKind.SyntaxList && c.pos <= node.pos && c.end >= node.end) {
30+
if (c.kind === SyntaxKind.SyntaxList && c.pos <= node.pos && c.end >= node.end) {
3131
return c;
3232
}
3333
});
3434

35+
// syntaxList should not be undefined here. If it is, there is a problem. Find out if
36+
// there at least is a child that is a list.
37+
if (!syntaxList) {
38+
Debug.assert(findChildOfKind(node.parent, SyntaxKind.SyntaxList),
39+
"Node of kind " + SyntaxKind[node.parent.kind] + " has no list children");
40+
}
41+
3542
return syntaxList;
3643
}
3744

0 commit comments

Comments
 (0)