-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7358 from martine/empty-return
in noImplicitReturns mode, also disallow "return;"
- Loading branch information
Showing
4 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/noImplicitReturnsWithoutReturnExpression.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
tests/cases/compiler/noImplicitReturnsWithoutReturnExpression.ts(2,5): error TS7030: Not all code paths return a value. | ||
tests/cases/compiler/noImplicitReturnsWithoutReturnExpression.ts(22,9): error TS7030: Not all code paths return a value. | ||
|
||
|
||
==== tests/cases/compiler/noImplicitReturnsWithoutReturnExpression.ts (2 errors) ==== | ||
function isMissingReturnExpression(): number { | ||
return; | ||
~~~~~~~ | ||
!!! error TS7030: Not all code paths return a value. | ||
} | ||
|
||
function isMissingReturnExpression2(): any { | ||
return; | ||
} | ||
|
||
function isMissingReturnExpression3(): number|void { | ||
return; | ||
} | ||
|
||
function isMissingReturnExpression4(): void { | ||
return; | ||
} | ||
|
||
function isMissingReturnExpression5(x) { | ||
if (x) { | ||
return 0; | ||
} | ||
else { | ||
return; | ||
~~~~~~~ | ||
!!! error TS7030: Not all code paths return a value. | ||
} | ||
} | ||
|
48 changes: 48 additions & 0 deletions
48
tests/baselines/reference/noImplicitReturnsWithoutReturnExpression.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//// [noImplicitReturnsWithoutReturnExpression.ts] | ||
function isMissingReturnExpression(): number { | ||
return; | ||
} | ||
|
||
function isMissingReturnExpression2(): any { | ||
return; | ||
} | ||
|
||
function isMissingReturnExpression3(): number|void { | ||
return; | ||
} | ||
|
||
function isMissingReturnExpression4(): void { | ||
return; | ||
} | ||
|
||
function isMissingReturnExpression5(x) { | ||
if (x) { | ||
return 0; | ||
} | ||
else { | ||
return; | ||
} | ||
} | ||
|
||
|
||
//// [noImplicitReturnsWithoutReturnExpression.js] | ||
function isMissingReturnExpression() { | ||
return; | ||
} | ||
function isMissingReturnExpression2() { | ||
return; | ||
} | ||
function isMissingReturnExpression3() { | ||
return; | ||
} | ||
function isMissingReturnExpression4() { | ||
return; | ||
} | ||
function isMissingReturnExpression5(x) { | ||
if (x) { | ||
return 0; | ||
} | ||
else { | ||
return; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/cases/compiler/noImplicitReturnsWithoutReturnExpression.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// @noImplicitReturns: true | ||
function isMissingReturnExpression(): number { | ||
return; | ||
} | ||
|
||
function isMissingReturnExpression2(): any { | ||
return; | ||
} | ||
|
||
function isMissingReturnExpression3(): number|void { | ||
return; | ||
} | ||
|
||
function isMissingReturnExpression4(): void { | ||
return; | ||
} | ||
|
||
function isMissingReturnExpression5(x) { | ||
if (x) { | ||
return 0; | ||
} | ||
else { | ||
return; | ||
} | ||
} |