mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 20:37:46 -05:00
Report grammatic and type-based unreachable code errors in the same way
This commit is contained in:
@@ -672,6 +672,9 @@ namespace ts {
|
||||
bindJSDoc(node);
|
||||
return;
|
||||
}
|
||||
if (node.kind >= SyntaxKind.FirstStatement && node.kind <= SyntaxKind.LastStatement) {
|
||||
node.flowNode = currentFlow;
|
||||
}
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.WhileStatement:
|
||||
bindWhileStatement(<WhileStatement>node);
|
||||
|
||||
@@ -17057,11 +17057,7 @@ namespace ts {
|
||||
// on empty arrays are possible without implicit any errors and new element types can be inferred without
|
||||
// type mismatch errors.
|
||||
const resultType = getObjectFlags(evolvedType) & ObjectFlags.EvolvingArray && isEvolvingArrayOperationTarget(reference) ? autoArrayType : finalizeEvolvingArrayType(evolvedType);
|
||||
if (resultType === unreachableNeverType) {
|
||||
error(reference, Diagnostics.Unreachable_code_detected);
|
||||
return declaredType;
|
||||
}
|
||||
if (reference.parent && reference.parent.kind === SyntaxKind.NonNullExpression && getTypeWithFacts(resultType, TypeFacts.NEUndefinedOrNull).flags & TypeFlags.Never) {
|
||||
if (resultType === unreachableNeverType|| reference.parent && reference.parent.kind === SyntaxKind.NonNullExpression && getTypeWithFacts(resultType, TypeFacts.NEUndefinedOrNull).flags & TypeFlags.Never) {
|
||||
return declaredType;
|
||||
}
|
||||
return resultType;
|
||||
@@ -30533,6 +30529,10 @@ namespace ts {
|
||||
cancellationToken.throwIfCancellationRequested();
|
||||
}
|
||||
}
|
||||
if (kind >= SyntaxKind.FirstStatement && kind <= SyntaxKind.LastStatement &&
|
||||
!compilerOptions.allowUnreachableCode && node.flowNode && !isReachableFlowNode(node.flowNode)) {
|
||||
errorOrSuggestion(compilerOptions.allowUnreachableCode === false, node, Diagnostics.Unreachable_code_detected);
|
||||
}
|
||||
|
||||
switch (kind) {
|
||||
case SyntaxKind.TypeParameter:
|
||||
|
||||
@@ -363,8 +363,8 @@ namespace ts {
|
||||
SemicolonClassElement,
|
||||
// Element
|
||||
Block,
|
||||
VariableStatement,
|
||||
EmptyStatement,
|
||||
VariableStatement,
|
||||
ExpressionStatement,
|
||||
IfStatement,
|
||||
DoStatement,
|
||||
@@ -514,6 +514,8 @@ namespace ts {
|
||||
LastTemplateToken = TemplateTail,
|
||||
FirstBinaryOperator = LessThanToken,
|
||||
LastBinaryOperator = CaretEqualsToken,
|
||||
FirstStatement = VariableStatement,
|
||||
LastStatement = DebuggerStatement,
|
||||
FirstNode = QualifiedName,
|
||||
FirstJSDocNode = JSDocTypeExpression,
|
||||
LastJSDocNode = JSDocPropertyTag,
|
||||
|
||||
Reference in New Issue
Block a user