diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 27e1b8117f441..9388827b85f64 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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 diff --git a/tests/baselines/reference/yieldExpressionInControlFlow.errors.txt b/tests/baselines/reference/yieldExpressionInControlFlow.errors.txt new file mode 100644 index 0000000000000..b571231172d53 --- /dev/null +++ b/tests/baselines/reference/yieldExpressionInControlFlow.errors.txt @@ -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. + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/yieldExpressionInControlFlow.symbols b/tests/baselines/reference/yieldExpressionInControlFlow.symbols new file mode 100644 index 0000000000000..1a0a2968dccfc --- /dev/null +++ b/tests/baselines/reference/yieldExpressionInControlFlow.symbols @@ -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)) + } +} + diff --git a/tests/baselines/reference/yieldExpressionInControlFlow.types b/tests/baselines/reference/yieldExpressionInControlFlow.types new file mode 100644 index 0000000000000..14650ef05829c --- /dev/null +++ b/tests/baselines/reference/yieldExpressionInControlFlow.types @@ -0,0 +1,38 @@ +=== tests/cases/conformance/es6/yieldExpressions/bug25149.js === +function* f() { +>f : () => IterableIterator + + 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 + + var o = [] +>o : any[] +>[] : undefined[] + + while (true) { +>true : true + + o = yield* o +>o = yield* o : any +>o : any[] +>yield* o : any +>o : any + } +} + diff --git a/tests/cases/conformance/es6/yieldExpressions/yieldExpressionInControlFlow.ts b/tests/cases/conformance/es6/yieldExpressions/yieldExpressionInControlFlow.ts new file mode 100644 index 0000000000000..fbabcbebce4ff --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/yieldExpressionInControlFlow.ts @@ -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 + } +}