Skip to content

Commit b2e8a39

Browse files
author
Andy Hanson
committed
Avoid infinite loop checking yield expression
1 parent 9f10888 commit b2e8a39

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
lines changed

src/compiler/checker.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19413,12 +19413,18 @@ namespace ts {
1941319413
function getTypeOfExpression(node: Expression, cache?: boolean) {
1941419414
// Optimize for the common case of a call to a function with a single non-generic call
1941519415
// signature where we can just fetch the return type without checking the arguments.
19416-
if (node.kind === SyntaxKind.CallExpression && (<CallExpression>node).expression.kind !== SyntaxKind.SuperKeyword && !isRequireCall(node, /*checkArgumentIsStringLiteral*/ true) && !isSymbolOrSymbolForCall(node)) {
19417-
const funcType = checkNonNullExpression((<CallExpression>node).expression);
19418-
const signature = getSingleCallSignature(funcType);
19419-
if (signature && !signature.typeParameters) {
19420-
return getReturnTypeOfSignature(signature);
19421-
}
19416+
switch (node.kind) {
19417+
case SyntaxKind.CallExpression:
19418+
if ((<CallExpression>node).expression.kind !== SyntaxKind.SuperKeyword && !isRequireCall(node, /*checkArgumentIsStringLiteral*/ true) && !isSymbolOrSymbolForCall(node)) {
19419+
const funcType = checkNonNullExpression((<CallExpression>node).expression);
19420+
const signature = getSingleCallSignature(funcType);
19421+
if (signature && !signature.typeParameters) {
19422+
return getReturnTypeOfSignature(signature);
19423+
}
19424+
}
19425+
break;
19426+
case SyntaxKind.YieldExpression:
19427+
return anyType;
1942219428
}
1942319429
// Otherwise simply call checkExpression. Ideally, the entire family of checkXXX functions
1942419430
// should have a parameter that indicates whether full error checking is required such that
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [yieldExpressionInFlowLoop.ts]
2+
function* f() {
3+
let result;
4+
while (1) {
5+
result = yield result;
6+
}
7+
}
8+
9+
10+
//// [yieldExpressionInFlowLoop.js]
11+
function* f() {
12+
let result;
13+
while (1) {
14+
result = yield result;
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/compiler/yieldExpressionInFlowLoop.ts ===
2+
function* f() {
3+
>f : Symbol(f, Decl(yieldExpressionInFlowLoop.ts, 0, 0))
4+
5+
let result;
6+
>result : Symbol(result, Decl(yieldExpressionInFlowLoop.ts, 1, 7))
7+
8+
while (1) {
9+
result = yield result;
10+
>result : Symbol(result, Decl(yieldExpressionInFlowLoop.ts, 1, 7))
11+
>result : Symbol(result, Decl(yieldExpressionInFlowLoop.ts, 1, 7))
12+
}
13+
}
14+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/yieldExpressionInFlowLoop.ts ===
2+
function* f() {
3+
>f : () => IterableIterator<any>
4+
5+
let result;
6+
>result : any
7+
8+
while (1) {
9+
>1 : 1
10+
11+
result = yield result;
12+
>result = yield result : any
13+
>result : any
14+
>yield result : any
15+
>result : any
16+
}
17+
}
18+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @noImplicitAny: true
2+
// @target: es6
3+
4+
function* f() {
5+
let result;
6+
while (1) {
7+
result = yield result;
8+
}
9+
}

0 commit comments

Comments
 (0)