Skip to content

Fix control flow loop in yield expression #25228

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

Merged
merged 2 commits into from
Jun 26, 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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19618,7 +19618,7 @@ namespace ts {

function getYieldedTypeOfYieldExpression(node: YieldExpression, isAsync: boolean, checkMode?: CheckMode): Type | undefined {
const errorNode = node.expression || node;
const expressionType = node.expression ? checkExpressionCached(node.expression, checkMode) : undefinedWideningType;
const expressionType = node.expression ? checkExpression(node.expression, checkMode) : undefinedWideningType;
// A `yield*` expression effectively yields everything that its operand yields
const yieldedType = node.asteriskToken ? checkIteratedTypeOrElementType(expressionType, errorNode, /*allowStringInput*/ false, isAsync) : expressionType;
return !isAsync ? yieldedType : getAwaitedType(yieldedType, errorNode, node.asteriskToken
Expand Down
25 changes: 25 additions & 0 deletions tests/baselines/reference/yieldExpressionInControlFlow.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
tests/cases/conformance/es6/yieldExpressions/alsoFails.ts(3,9): error TS7034: Variable 'o' implicitly has type 'any[]' in some locations where its type cannot be determined.
tests/cases/conformance/es6/yieldExpressions/alsoFails.ts(5,20): error TS7005: Variable 'o' implicitly has an 'any[]' type.


==== tests/cases/conformance/es6/yieldExpressions/bug25149.js (0 errors) ====
function* f() {
var o
while (true) {
o = yield o
}
}

==== tests/cases/conformance/es6/yieldExpressions/alsoFails.ts (2 errors) ====
// fails in Typescript too
function* g() {
var o = []
~
!!! error TS7034: Variable 'o' implicitly has type 'any[]' in some locations where its type cannot be determined.
while (true) {
o = yield* o
~
!!! error TS7005: Variable 'o' implicitly has an 'any[]' type.
}
}

29 changes: 29 additions & 0 deletions tests/baselines/reference/yieldExpressionInControlFlow.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
=== tests/cases/conformance/es6/yieldExpressions/bug25149.js ===
function* f() {
>f : Symbol(f, Decl(bug25149.js, 0, 0))

var o
>o : Symbol(o, Decl(bug25149.js, 1, 7))

while (true) {
o = yield o
>o : Symbol(o, Decl(bug25149.js, 1, 7))
>o : Symbol(o, Decl(bug25149.js, 1, 7))
}
}

=== tests/cases/conformance/es6/yieldExpressions/alsoFails.ts ===
// fails in Typescript too
function* g() {
>g : Symbol(g, Decl(alsoFails.ts, 0, 0))

var o = []
>o : Symbol(o, Decl(alsoFails.ts, 2, 7))

while (true) {
o = yield* o
>o : Symbol(o, Decl(alsoFails.ts, 2, 7))
>o : Symbol(o, Decl(alsoFails.ts, 2, 7))
}
}

38 changes: 38 additions & 0 deletions tests/baselines/reference/yieldExpressionInControlFlow.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
=== tests/cases/conformance/es6/yieldExpressions/bug25149.js ===
function* f() {
>f : () => IterableIterator<any>

var o
>o : any

while (true) {
>true : true

o = yield o
>o = yield o : any
>o : any
>yield o : any
>o : any
}
}

=== tests/cases/conformance/es6/yieldExpressions/alsoFails.ts ===
// fails in Typescript too
function* g() {
>g : () => IterableIterator<any>

var o = []
>o : any[]
>[] : undefined[]

while (true) {
>true : true

o = yield* o
>o = yield* o : any
>o : any[]
>yield* o : any
>o : any
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @noEmit: true
// @allowJs: true
// @checkJs: true
// @noImplicitAny: true
// @lib: esnext
// @Filename: bug25149.js
function* f() {
var o
while (true) {
o = yield o
}
}

// @Filename: alsoFails.ts
// fails in Typescript too
function* g() {
var o = []
while (true) {
o = yield* o
}
}