Skip to content

Commit 8619bff

Browse files
committed
Error on assertion and non-returning function calls that aren't CFA-ed
1 parent 3dd7b84 commit 8619bff

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

src/compiler/binder.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,12 +1287,6 @@ namespace ts {
12871287
activeLabels!.pop();
12881288
}
12891289

1290-
function isDottedName(node: Expression): boolean {
1291-
return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.ThisKeyword ||
1292-
node.kind === SyntaxKind.PropertyAccessExpression && isDottedName((<PropertyAccessExpression>node).expression) ||
1293-
node.kind === SyntaxKind.ParenthesizedExpression && isDottedName((<ParenthesizedExpression>node).expression);
1294-
}
1295-
12961290
function bindExpressionStatement(node: ExpressionStatement): void {
12971291
bind(node.expression);
12981292
// A top level call expression with a dotted function name and at least one argument

src/compiler/checker.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23416,6 +23416,15 @@ namespace ts {
2341623416
if (returnType.flags & TypeFlags.ESSymbolLike && isSymbolOrSymbolForCall(node)) {
2341723417
return getESSymbolLikeTypeForNode(walkUpParenthesizedExpressions(node.parent));
2341823418
}
23419+
if (node.kind === SyntaxKind.CallExpression && node.parent.kind === SyntaxKind.ExpressionStatement &&
23420+
returnType.flags & (TypeFlags.Void | TypeFlags.Never) && hasTypePredicateOrNeverReturnType(signature)) {
23421+
if (!isDottedName(node.expression)) {
23422+
error(node.expression, Diagnostics.Control_flow_effects_of_calls_to_assertion_and_never_returning_functions_are_reflected_only_when_the_function_expression_is_an_identifier_or_qualified_name);
23423+
}
23424+
else if (!getEffectsSignature(node)) {
23425+
error(node.expression, Diagnostics.Control_flow_effects_of_calls_to_assertion_and_never_returning_functions_are_reflected_only_when_every_variable_or_property_referenced_in_the_function_expression_is_declared_with_an_explicit_type_annotation);
23426+
}
23427+
}
2341923428
let jsAssignmentType: Type | undefined;
2342023429
if (isInJSFile(node)) {
2342123430
const decl = getDeclarationOfExpando(node);

src/compiler/diagnosticMessages.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,6 +2726,14 @@
27262726
"category": "Error",
27272727
"code": 2774
27282728
},
2729+
"Control flow effects of calls to assertion and never-returning functions are reflected only when every variable or property referenced in the function expression is declared with an explicit type annotation.": {
2730+
"category": "Error",
2731+
"code": 2775
2732+
},
2733+
"Control flow effects of calls to assertion and never-returning functions are reflected only when the function expression is an identifier or qualified-name.": {
2734+
"category": "Error",
2735+
"code": 2776
2736+
},
27292737
"Import declaration '{0}' is using private name '{1}'.": {
27302738
"category": "Error",
27312739
"code": 4000

src/compiler/utilities.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4062,6 +4062,12 @@ namespace ts {
40624062
return node.kind === SyntaxKind.Identifier || isPropertyAccessEntityNameExpression(node);
40634063
}
40644064

4065+
export function isDottedName(node: Expression): boolean {
4066+
return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.ThisKeyword ||
4067+
node.kind === SyntaxKind.PropertyAccessExpression && isDottedName((<PropertyAccessExpression>node).expression) ||
4068+
node.kind === SyntaxKind.ParenthesizedExpression && isDottedName((<ParenthesizedExpression>node).expression);
4069+
}
4070+
40654071
export function isPropertyAccessEntityNameExpression(node: Node): node is PropertyAccessEntityNameExpression {
40664072
return isPropertyAccessExpression(node) && isEntityNameExpression(node.expression);
40674073
}

0 commit comments

Comments
 (0)