Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat 'yield;' as 'yield undefined;' #22297

Merged
3 commits merged into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18525,9 +18525,7 @@ namespace ts {
const aggregatedTypes: Type[] = [];
const isAsync = (getFunctionFlags(func) & FunctionFlags.Async) !== 0;
forEachYieldExpression(<Block>func.body, yieldExpression => {
if (yieldExpression.expression) { // TODO: GH#22297
pushIfUnique(aggregatedTypes, getYieldedTypeOfYieldExpression(yieldExpression, isAsync, checkMode));
}
pushIfUnique(aggregatedTypes, getYieldedTypeOfYieldExpression(yieldExpression, isAsync, checkMode));
});
return aggregatedTypes;
}
Expand Down Expand Up @@ -19520,8 +19518,6 @@ namespace ts {
}
}

if (!node.expression) return anyType; // TODO: GH#22297

const isAsync = (functionFlags & FunctionFlags.Async) !== 0;
const yieldedType = getYieldedTypeOfYieldExpression(node, isAsync);
// There is no point in doing an assignability check if the function
Expand Down
18 changes: 13 additions & 5 deletions tests/baselines/reference/generatorTypeCheck48.errors.txt
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;
}

10 changes: 9 additions & 1 deletion tests/baselines/reference/generatorTypeCheck48.js
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;
}
8 changes: 8 additions & 0 deletions tests/baselines/reference/generatorTypeCheck48.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ function* g() {

yield;
}

function* h() {
>h : Symbol(h, Decl(generatorTypeCheck48.ts, 2, 1))

yield undefined;
>undefined : Symbol(undefined)
}

9 changes: 9 additions & 0 deletions tests/baselines/reference/generatorTypeCheck48.types
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ function* g() {
yield;
>yield : any
}

function* h() {
>h : () => IterableIterator<any>

yield undefined;
>yield undefined : any
>undefined : undefined
}

16 changes: 16 additions & 0 deletions tests/baselines/reference/yieldExpression1.errors.txt
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;
}

20 changes: 16 additions & 4 deletions tests/baselines/reference/yieldExpression1.js
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;
}
16 changes: 13 additions & 3 deletions tests/baselines/reference/yieldExpression1.symbols
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;
}

23 changes: 20 additions & 3 deletions tests/baselines/reference/yieldExpression1.types
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
}

14 changes: 11 additions & 3 deletions tests/cases/compiler/yieldExpression1.ts
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@

function* g() {
yield;
}
}

function* h() {
yield undefined;
}