Skip to content

Commit 5daf0c0

Browse files
committed
exclude iffes from getContextualType
1 parent 6152848 commit 5daf0c0

File tree

4 files changed

+121
-0
lines changed

4 files changed

+121
-0
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32149,6 +32149,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3214932149
case SyntaxKind.CallExpression:
3215032150
case SyntaxKind.NewExpression:
3215132151
if (node === (parent as CallExpression | NewExpression).expression) {
32152+
if (getImmediatelyInvokedFunctionExpression(skipParentheses(node))) {
32153+
// iifes themselves can't be contextually-typed (unlike their parameters)
32154+
return undefined;
32155+
}
3215232156
return getContextualType(parent as CallExpression | NewExpression, contextFlags);
3215332157
}
3215432158
return getContextualTypeForArgument(parent as CallExpression | NewExpression, node);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//// [tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck64.ts] ////
2+
3+
=== generatorTypeCheck64.ts ===
4+
function* g3(): Generator<Generator<(x: string) => number>> {
5+
>g3 : Symbol(g3, Decl(generatorTypeCheck64.ts, 0, 0))
6+
>Generator : Symbol(Generator, Decl(lib.es2015.generator.d.ts, --, --))
7+
>Generator : Symbol(Generator, Decl(lib.es2015.generator.d.ts, --, --))
8+
>x : Symbol(x, Decl(generatorTypeCheck64.ts, 0, 37))
9+
10+
yield function* () {
11+
yield x => x.length;
12+
>x : Symbol(x, Decl(generatorTypeCheck64.ts, 2, 13))
13+
>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
14+
>x : Symbol(x, Decl(generatorTypeCheck64.ts, 2, 13))
15+
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
16+
17+
} ()
18+
}
19+
20+
function* g4(): Iterator<Iterable<(x: string) => number>> {
21+
>g4 : Symbol(g4, Decl(generatorTypeCheck64.ts, 4, 1))
22+
>Iterator : Symbol(Iterator, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.esnext.iterator.d.ts, --, --))
23+
>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --))
24+
>x : Symbol(x, Decl(generatorTypeCheck64.ts, 6, 35))
25+
26+
yield (function* () {
27+
yield (x) => x.length;
28+
>x : Symbol(x, Decl(generatorTypeCheck64.ts, 8, 11))
29+
>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
30+
>x : Symbol(x, Decl(generatorTypeCheck64.ts, 8, 11))
31+
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
32+
33+
})();
34+
}
35+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//// [tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck64.ts] ////
2+
3+
=== Performance Stats ===
4+
Type Count: 1,000
5+
Instantiation count: 2,500
6+
7+
=== generatorTypeCheck64.ts ===
8+
function* g3(): Generator<Generator<(x: string) => number>> {
9+
>g3 : () => Generator<Generator<(x: string) => number>>
10+
> : ^^^^^^
11+
>x : string
12+
> : ^^^^^^
13+
14+
yield function* () {
15+
>yield function* () { yield x => x.length; } () : any
16+
>function* () { yield x => x.length; } () : Generator<(x: string) => number, void, any>
17+
> : ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
>function* () { yield x => x.length; } : () => Generator<(x: string) => number, void, any>
19+
> : ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
21+
yield x => x.length;
22+
>yield x => x.length : any
23+
>x => x.length : (x: string) => number
24+
> : ^ ^^^^^^^^^^^^^^^^^^^
25+
>x : string
26+
> : ^^^^^^
27+
>x.length : number
28+
> : ^^^^^^
29+
>x : string
30+
> : ^^^^^^
31+
>length : number
32+
> : ^^^^^^
33+
34+
} ()
35+
}
36+
37+
function* g4(): Iterator<Iterable<(x: string) => number>> {
38+
>g4 : () => Iterator<Iterable<(x: string) => number>>
39+
> : ^^^^^^
40+
>x : string
41+
> : ^^^^^^
42+
43+
yield (function* () {
44+
>yield (function* () { yield (x) => x.length; })() : any
45+
>(function* () { yield (x) => x.length; })() : Generator<(x: string) => number, void, any>
46+
> : ^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47+
>(function* () { yield (x) => x.length; }) : () => Generator<(x: string) => number, void, any>
48+
> : ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49+
>function* () { yield (x) => x.length; } : () => Generator<(x: string) => number, void, any>
50+
> : ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
51+
52+
yield (x) => x.length;
53+
>yield (x) => x.length : any
54+
>(x) => x.length : (x: string) => number
55+
> : ^ ^^^^^^^^^^^^^^^^^^^
56+
>x : string
57+
> : ^^^^^^
58+
>x.length : number
59+
> : ^^^^^^
60+
>x : string
61+
> : ^^^^^^
62+
>length : number
63+
> : ^^^^^^
64+
65+
})();
66+
}
67+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @strict: true
2+
// @target: esnext
3+
// @noEmit: true
4+
5+
function* g3(): Generator<Generator<(x: string) => number>> {
6+
yield function* () {
7+
yield x => x.length;
8+
} ()
9+
}
10+
11+
function* g4(): Iterator<Iterable<(x: string) => number>> {
12+
yield (function* () {
13+
yield (x) => x.length;
14+
})();
15+
}

0 commit comments

Comments
 (0)