Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f6603cd

Browse filesBrowse files
Merge pull request microsoft#20545 from RyanCavanaugh/codefixOmnibus
Omnibus fixes for telemetry-sourced crashes
2 parents 8f8e6a3 + 92c3b23 commit f6603cd
Copy full SHA for f6603cd

7 files changed

+55-5Lines changed: 55 additions & 5 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/checker.ts‎

Copy file name to clipboardExpand all lines: src/compiler/checker.ts
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3951,7 +3951,12 @@ namespace ts {
39513951
writePunctuation(writer, SyntaxKind.CloseBracketToken);
39523952
writePunctuation(writer, SyntaxKind.ColonToken);
39533953
writeSpace(writer);
3954-
buildTypeDisplay(info.type, writer, enclosingDeclaration, globalFlags, symbolStack);
3954+
if (info.type) {
3955+
buildTypeDisplay(info.type, writer, enclosingDeclaration, globalFlags, symbolStack);
3956+
}
3957+
else {
3958+
writeKeyword(writer, SyntaxKind.AnyKeyword);
3959+
}
39553960
writePunctuation(writer, SyntaxKind.SemicolonToken);
39563961
writer.writeLine();
39573962
}
Collapse file

‎src/services/codefixes/inferFromUsage.ts‎

Copy file name to clipboardExpand all lines: src/services/codefixes/inferFromUsage.ts
+19-3Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ namespace ts.codefix {
7070
return undefined;
7171
}
7272

73-
const containingFunction = getContainingFunction(token);
7473
switch (errorCode) {
7574
// Variable and Property declarations
7675
case Diagnostics.Member_0_implicitly_has_an_1_type.code:
@@ -81,6 +80,13 @@ namespace ts.codefix {
8180
const symbol = program.getTypeChecker().getSymbolAtLocation(token);
8281
return symbol && symbol.valueDeclaration && getCodeActionForVariableDeclaration(<VariableDeclaration>symbol.valueDeclaration, sourceFile, program, cancellationToken);
8382
}
83+
}
84+
85+
const containingFunction = getContainingFunction(token);
86+
if (containingFunction === undefined) {
87+
return undefined;
88+
}
89+
switch (errorCode) {
8490

8591
// Parameter declarations
8692
case Diagnostics.Parameter_0_implicitly_has_an_1_type.code:
@@ -148,6 +154,11 @@ namespace ts.codefix {
148154
containingFunction.parameters.map(p => isIdentifier(p.name) ? inferTypeForVariableFromUsage(p.name, sourceFile, program, cancellationToken) : undefined);
149155
if (!types) return undefined;
150156

157+
// We didn't actually find a set of type inference positions matching each parameter position
158+
if (containingFunction.parameters.length !== types.length) {
159+
return undefined;
160+
}
161+
151162
const textChanges = arrayFrom(mapDefinedIterator(zipToIterator(containingFunction.parameters, types), ([parameter, type]) =>
152163
type && !parameter.type && !parameter.initializer ? makeChange(containingFunction, parameter.end, type, program) : undefined));
153164
return textChanges.length ? { declaration: parameterDeclaration, textChanges } : undefined;
@@ -191,8 +202,9 @@ namespace ts.codefix {
191202
sourceFile,
192203
token.getStart(sourceFile));
193204

194-
Debug.assert(!!references, "Found no references!");
195-
Debug.assert(references.length === 1, "Found more references than expected");
205+
if (!references || references.length !== 1) {
206+
return [];
207+
}
196208

197209
return references[0].references.map(r => <Identifier>getTokenAtPosition(program.getSourceFile(r.fileName), r.textSpan.start, /*includeJsDocComment*/ false));
198210
}
@@ -281,6 +293,10 @@ namespace ts.codefix {
281293
}
282294

283295
export function inferTypeForParametersFromReferences(references: Identifier[], declaration: FunctionLikeDeclaration, checker: TypeChecker, cancellationToken: CancellationToken): (Type | undefined)[] | undefined {
296+
if (references.length === 0) {
297+
return undefined;
298+
}
299+
284300
if (declaration.parameters) {
285301
const usageContext: UsageContext = {};
286302
for (const reference of references) {
Collapse file

‎src/services/symbolDisplay.ts‎

Copy file name to clipboardExpand all lines: src/services/symbolDisplay.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ namespace ts.SymbolDisplay {
496496
addNewLineIfDisplayPartsExist();
497497
if (symbolKind) {
498498
pushTypePart(symbolKind);
499-
if (!some(symbol.declarations, d => isArrowFunction(d) || (isFunctionExpression(d) || isClassExpression(d)) && !d.name)) {
499+
if (symbol && !some(symbol.declarations, d => isArrowFunction(d) || (isFunctionExpression(d) || isClassExpression(d)) && !d.name)) {
500500
displayParts.push(spacePart());
501501
addFullSymbolName(symbol);
502502
}
Collapse file
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @noImplicitAny: true
4+
//// function f(/*1*/x) {
5+
//// }
6+
//// f(
7+
8+
verify.not.codeFixAvailable([]);
9+
Collapse file
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @noImplicitAny: true
4+
//// function f(new C(100, 3, undefined)
5+
6+
verify.not.codeFixAvailable([]);
7+
Collapse file
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @noImplicitAny: true
4+
//// function ...q) {}} f(10);
5+
6+
verify.not.codeFixAvailable([]);
7+
Collapse file
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @noImplicitAny: true
4+
//// function f(y, z = { p: y[
5+
6+
verify.getAndApplyCodeFix();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.