Merge pull request #7500 from Microsoft/noImplicitReturnCtor

don't check that return statement has expression in constructors
This commit is contained in:
Vladimir Matveev 2016-03-13 18:52:17 -07:00
commit 94ada07051
5 changed files with 37 additions and 1 deletions

View file

@ -13965,7 +13965,7 @@ namespace ts {
}
}
}
else if (compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeVoidOrAny(func, returnType)) {
else if (func.kind !== SyntaxKind.Constructor && compilerOptions.noImplicitReturns && !isUnwrappedReturnTypeVoidOrAny(func, returnType)) {
// 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);
}

View file

@ -0,0 +1,14 @@
//// [noImplicitReturnInConstructors.ts]
class C {
constructor() {
return;
}
}
//// [noImplicitReturnInConstructors.js]
var C = (function () {
function C() {
return;
}
return C;
}());

View file

@ -0,0 +1,8 @@
=== tests/cases/compiler/noImplicitReturnInConstructors.ts ===
class C {
>C : Symbol(C, Decl(noImplicitReturnInConstructors.ts, 0, 0))
constructor() {
return;
}
}

View file

@ -0,0 +1,8 @@
=== tests/cases/compiler/noImplicitReturnInConstructors.ts ===
class C {
>C : C
constructor() {
return;
}
}

View file

@ -0,0 +1,6 @@
// @noImplicitReturns: true
class C {
constructor() {
return;
}
}