-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Treat 'yield;' as 'yield undefined;' (#22297)
* Treat 'yield;' as 'yield undefined;' * Use undefinedWideningType
- Loading branch information
Andy
authored
Mar 8, 2018
1 parent
28e8c4f
commit e48bcd6
Showing
11 changed files
with
121 additions
and
25 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
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 |
---|---|---|
@@ -1,9 +1,17 @@ | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts(1,9): error TS7025: Generator implicitly has type 'IterableIterator<any>' because it does not yield any values. Consider supplying a return type. | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts(1,11): error TS7010: 'g', which lacks return-type annotation, implicitly has an 'any' return type. | ||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts(5,11): error TS7010: 'h', which lacks return-type annotation, implicitly has an 'any' return type. | ||
|
||
|
||
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts (1 errors) ==== | ||
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts (2 errors) ==== | ||
function* g() { | ||
~ | ||
!!! error TS7025: Generator implicitly has type 'IterableIterator<any>' because it does not yield any values. Consider supplying a return type. | ||
~ | ||
!!! error TS7010: 'g', which lacks return-type annotation, implicitly has an 'any' return type. | ||
yield; | ||
} | ||
} | ||
|
||
function* h() { | ||
~ | ||
!!! error TS7010: 'h', which lacks return-type annotation, implicitly has an 'any' return type. | ||
yield undefined; | ||
} | ||
|
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 |
---|---|---|
@@ -1,9 +1,17 @@ | ||
//// [generatorTypeCheck48.ts] | ||
function* g() { | ||
yield; | ||
} | ||
} | ||
|
||
function* h() { | ||
yield undefined; | ||
} | ||
|
||
|
||
//// [generatorTypeCheck48.js] | ||
function* g() { | ||
yield; | ||
} | ||
function* h() { | ||
yield undefined; | ||
} |
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
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
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,16 @@ | ||
tests/cases/compiler/yieldExpression1.ts(7,5): error TS2322: Type 'undefined' is not assignable to type 'number'. | ||
|
||
|
||
==== tests/cases/compiler/yieldExpression1.ts (1 errors) ==== | ||
function* a() { | ||
yield; | ||
yield 0; | ||
} | ||
|
||
function* b(): IterableIterator<number> { | ||
yield; | ||
~~~~~ | ||
!!! error TS2322: Type 'undefined' is not assignable to type 'number'. | ||
yield 0; | ||
} | ||
|
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 |
---|---|---|
@@ -1,9 +1,21 @@ | ||
//// [yieldExpression1.ts] | ||
function* foo() { | ||
yield | ||
} | ||
function* a() { | ||
yield; | ||
yield 0; | ||
} | ||
|
||
function* b(): IterableIterator<number> { | ||
yield; | ||
yield 0; | ||
} | ||
|
||
|
||
//// [yieldExpression1.js] | ||
function* foo() { | ||
function* a() { | ||
yield; | ||
yield 0; | ||
} | ||
function* b() { | ||
yield; | ||
yield 0; | ||
} |
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 |
---|---|---|
@@ -1,6 +1,16 @@ | ||
=== tests/cases/compiler/yieldExpression1.ts === | ||
function* foo() { | ||
>foo : Symbol(foo, Decl(yieldExpression1.ts, 0, 0)) | ||
function* a() { | ||
>a : Symbol(a, Decl(yieldExpression1.ts, 0, 0)) | ||
|
||
yield | ||
yield; | ||
yield 0; | ||
} | ||
|
||
function* b(): IterableIterator<number> { | ||
>b : Symbol(b, Decl(yieldExpression1.ts, 3, 1)) | ||
>IterableIterator : Symbol(IterableIterator, Decl(lib.es2015.iterable.d.ts, --, --)) | ||
|
||
yield; | ||
yield 0; | ||
} | ||
|
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 |
---|---|---|
@@ -1,7 +1,24 @@ | ||
=== tests/cases/compiler/yieldExpression1.ts === | ||
function* foo() { | ||
>foo : () => IterableIterator<any> | ||
function* a() { | ||
>a : () => IterableIterator<0 | undefined> | ||
|
||
yield | ||
yield; | ||
>yield : any | ||
|
||
yield 0; | ||
>yield 0 : any | ||
>0 : 0 | ||
} | ||
|
||
function* b(): IterableIterator<number> { | ||
>b : () => IterableIterator<number> | ||
>IterableIterator : IterableIterator<T> | ||
|
||
yield; | ||
>yield : any | ||
|
||
yield 0; | ||
>yield 0 : any | ||
>0 : 0 | ||
} | ||
|
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 |
---|---|---|
@@ -1,4 +1,12 @@ | ||
// @target: es6 | ||
function* foo() { | ||
yield | ||
} | ||
// @strictNullChecks: true | ||
|
||
function* a() { | ||
yield; | ||
yield 0; | ||
} | ||
|
||
function* b(): IterableIterator<number> { | ||
yield; | ||
yield 0; | ||
} |
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 |
---|---|---|
|
@@ -3,4 +3,8 @@ | |
|
||
function* g() { | ||
yield; | ||
} | ||
} | ||
|
||
function* h() { | ||
yield undefined; | ||
} |