Skip to content

Commit 9025bc7

Browse files
authored
Fix control flow loop in yield expression (microsoft#25228)
* Fix control flow loop in yield expression Yet again, the fix is to stop using checkExpressionCached. * Update lib in test to reduce number of errors
1 parent 9044589 commit 9025bc7

File tree

5 files changed

+114
-1
lines changed

5 files changed

+114
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19911,7 +19911,7 @@ namespace ts {
1991119911

1991219912
function getYieldedTypeOfYieldExpression(node: YieldExpression, isAsync: boolean, checkMode?: CheckMode): Type | undefined {
1991319913
const errorNode = node.expression || node;
19914-
const expressionType = node.expression ? checkExpressionCached(node.expression, checkMode) : undefinedWideningType;
19914+
const expressionType = node.expression ? checkExpression(node.expression, checkMode) : undefinedWideningType;
1991519915
// A `yield*` expression effectively yields everything that its operand yields
1991619916
const yieldedType = node.asteriskToken ? checkIteratedTypeOrElementType(expressionType, errorNode, /*allowStringInput*/ false, isAsync) : expressionType;
1991719917
return !isAsync ? yieldedType : getAwaitedType(yieldedType, errorNode, node.asteriskToken
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
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.
2+
tests/cases/conformance/es6/yieldExpressions/alsoFails.ts(5,20): error TS7005: Variable 'o' implicitly has an 'any[]' type.
3+
4+
5+
==== tests/cases/conformance/es6/yieldExpressions/bug25149.js (0 errors) ====
6+
function* f() {
7+
var o
8+
while (true) {
9+
o = yield o
10+
}
11+
}
12+
13+
==== tests/cases/conformance/es6/yieldExpressions/alsoFails.ts (2 errors) ====
14+
// fails in Typescript too
15+
function* g() {
16+
var o = []
17+
~
18+
!!! error TS7034: Variable 'o' implicitly has type 'any[]' in some locations where its type cannot be determined.
19+
while (true) {
20+
o = yield* o
21+
~
22+
!!! error TS7005: Variable 'o' implicitly has an 'any[]' type.
23+
}
24+
}
25+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
=== tests/cases/conformance/es6/yieldExpressions/bug25149.js ===
2+
function* f() {
3+
>f : Symbol(f, Decl(bug25149.js, 0, 0))
4+
5+
var o
6+
>o : Symbol(o, Decl(bug25149.js, 1, 7))
7+
8+
while (true) {
9+
o = yield o
10+
>o : Symbol(o, Decl(bug25149.js, 1, 7))
11+
>o : Symbol(o, Decl(bug25149.js, 1, 7))
12+
}
13+
}
14+
15+
=== tests/cases/conformance/es6/yieldExpressions/alsoFails.ts ===
16+
// fails in Typescript too
17+
function* g() {
18+
>g : Symbol(g, Decl(alsoFails.ts, 0, 0))
19+
20+
var o = []
21+
>o : Symbol(o, Decl(alsoFails.ts, 2, 7))
22+
23+
while (true) {
24+
o = yield* o
25+
>o : Symbol(o, Decl(alsoFails.ts, 2, 7))
26+
>o : Symbol(o, Decl(alsoFails.ts, 2, 7))
27+
}
28+
}
29+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
=== tests/cases/conformance/es6/yieldExpressions/bug25149.js ===
2+
function* f() {
3+
>f : () => IterableIterator<any>
4+
5+
var o
6+
>o : any
7+
8+
while (true) {
9+
>true : true
10+
11+
o = yield o
12+
>o = yield o : any
13+
>o : any
14+
>yield o : any
15+
>o : any
16+
}
17+
}
18+
19+
=== tests/cases/conformance/es6/yieldExpressions/alsoFails.ts ===
20+
// fails in Typescript too
21+
function* g() {
22+
>g : () => IterableIterator<any>
23+
24+
var o = []
25+
>o : any[]
26+
>[] : undefined[]
27+
28+
while (true) {
29+
>true : true
30+
31+
o = yield* o
32+
>o = yield* o : any
33+
>o : any[]
34+
>yield* o : any
35+
>o : any
36+
}
37+
}
38+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @noEmit: true
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @noImplicitAny: true
5+
// @lib: esnext
6+
// @Filename: bug25149.js
7+
function* f() {
8+
var o
9+
while (true) {
10+
o = yield o
11+
}
12+
}
13+
14+
// @Filename: alsoFails.ts
15+
// fails in Typescript too
16+
function* g() {
17+
var o = []
18+
while (true) {
19+
o = yield* o
20+
}
21+
}

0 commit comments

Comments
 (0)