Merge pull request #7358 from martine/empty-return

in noImplicitReturns mode, also disallow "return;"
This commit is contained in:
Mohamed Hegazy
2016-03-03 13:56:19 -08:00
4 changed files with 116 additions and 5 deletions
+9 -5
View File
@@ -13848,11 +13848,11 @@ namespace ts {
}
}
if (node.expression) {
const func = getContainingFunction(node);
if (func) {
const signature = getSignatureFromDeclaration(func);
const returnType = getReturnTypeOfSignature(signature);
const func = getContainingFunction(node);
if (func) {
const signature = getSignatureFromDeclaration(func);
const returnType = getReturnTypeOfSignature(signature);
if (node.expression) {
const exprType = checkExpressionCached(node.expression);
if (func.asteriskToken) {
@@ -13887,6 +13887,10 @@ namespace ts {
}
}
}
else if (compilerOptions.noImplicitReturns && !maybeTypeOfKind(returnType, TypeFlags.Void | TypeFlags.Any)) {
// The function has a return type, but the return statement doesn't have an expression.
error(node, Diagnostics.Not_all_code_paths_return_a_value);
}
}
}