Merge pull request #7358 from martine/empty-return

in noImplicitReturns mode, also disallow "return;"
This commit is contained in:
Mohamed Hegazy committed 2016-03-03 13:56:19 -08:00
commit 0cba37d5b2
4 files changed
+116 -5

No files matched your search

+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);
}
}
}