Skip to content

Commit 91f89b9

Browse files
authored
Visit child nodes in checkExpressionWithTypeArguments (#51804)
* Visit child nodes in checkExpressionWithTypeArguments * Accept new baselines * Add tests
1 parent a77a79f commit 91f89b9

9 files changed

+355
-4
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33609,6 +33609,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
3360933609

3361033610
function checkExpressionWithTypeArguments(node: ExpressionWithTypeArguments | TypeQueryNode) {
3361133611
checkGrammarExpressionWithTypeArguments(node);
33612+
forEach(node.typeArguments, checkSourceElement);
3361233613
const exprType = node.kind === SyntaxKind.ExpressionWithTypeArguments ? checkExpression(node.expression) :
3361333614
isThisIdentifier(node.exprName) ? checkThisExpression(node.exprName) :
3361433615
checkExpression(node.exprName);
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(9,21): error TS8020: JSDoc types can only be used inside documentation comments.
2+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(10,20): error TS8020: JSDoc types can only be used inside documentation comments.
3+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(11,21): error TS8020: JSDoc types can only be used inside documentation comments.
4+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(12,23): error TS8020: JSDoc types can only be used inside documentation comments.
5+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(12,24): error TS8020: JSDoc types can only be used inside documentation comments.
6+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(14,28): error TS8020: JSDoc types can only be used inside documentation comments.
7+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(15,27): error TS8020: JSDoc types can only be used inside documentation comments.
8+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(16,28): error TS8020: JSDoc types can only be used inside documentation comments.
9+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(17,30): error TS8020: JSDoc types can only be used inside documentation comments.
10+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(17,31): error TS8020: JSDoc types can only be used inside documentation comments.
11+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(19,21): error TS8020: JSDoc types can only be used inside documentation comments.
12+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(20,20): error TS8020: JSDoc types can only be used inside documentation comments.
13+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(21,21): error TS8020: JSDoc types can only be used inside documentation comments.
14+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(22,23): error TS8020: JSDoc types can only be used inside documentation comments.
15+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(22,24): error TS8020: JSDoc types can only be used inside documentation comments.
16+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(24,28): error TS8020: JSDoc types can only be used inside documentation comments.
17+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(25,27): error TS8020: JSDoc types can only be used inside documentation comments.
18+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(26,28): error TS8020: JSDoc types can only be used inside documentation comments.
19+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(27,30): error TS8020: JSDoc types can only be used inside documentation comments.
20+
tests/cases/compiler/expressionWithJSDocTypeArguments.ts(27,31): error TS8020: JSDoc types can only be used inside documentation comments.
21+
22+
23+
==== tests/cases/compiler/expressionWithJSDocTypeArguments.ts (20 errors) ====
24+
// Repro from #51802
25+
26+
function foo<T>(x: T): T { return x }
27+
28+
class Bar<T> { constructor(public x: T) { } }
29+
30+
// Errors expected on all of the following
31+
32+
const WhatFoo = foo<?>;
33+
~
34+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
35+
const HuhFoo = foo<string?>;
36+
~~~~~~~
37+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
38+
const NopeFoo = foo<?string>;
39+
~~~~~~~
40+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
41+
const ComeOnFoo = foo<?string?>;
42+
~~~~~~~~
43+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
44+
~~~~~~~
45+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
46+
47+
type TWhatFoo = typeof foo<?>;
48+
~
49+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
50+
type THuhFoo = typeof foo<string?>;
51+
~~~~~~~
52+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
53+
type TNopeFoo = typeof foo<?string>;
54+
~~~~~~~
55+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
56+
type TComeOnFoo = typeof foo<?string?>;
57+
~~~~~~~~
58+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
59+
~~~~~~~
60+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
61+
62+
const WhatBar = Bar<?>;
63+
~
64+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
65+
const HuhBar = Bar<string?>;
66+
~~~~~~~
67+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
68+
const NopeBar = Bar<?string>;
69+
~~~~~~~
70+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
71+
const ComeOnBar = Bar<?string?>;
72+
~~~~~~~~
73+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
74+
~~~~~~~
75+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
76+
77+
type TWhatBar = typeof Bar<?>;
78+
~
79+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
80+
type THuhBar = typeof Bar<string?>;
81+
~~~~~~~
82+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
83+
type TNopeBar = typeof Bar<?string>;
84+
~~~~~~~
85+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
86+
type TComeOnBar = typeof Bar<?string?>;
87+
~~~~~~~~
88+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
89+
~~~~~~~
90+
!!! error TS8020: JSDoc types can only be used inside documentation comments.
91+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//// [expressionWithJSDocTypeArguments.ts]
2+
// Repro from #51802
3+
4+
function foo<T>(x: T): T { return x }
5+
6+
class Bar<T> { constructor(public x: T) { } }
7+
8+
// Errors expected on all of the following
9+
10+
const WhatFoo = foo<?>;
11+
const HuhFoo = foo<string?>;
12+
const NopeFoo = foo<?string>;
13+
const ComeOnFoo = foo<?string?>;
14+
15+
type TWhatFoo = typeof foo<?>;
16+
type THuhFoo = typeof foo<string?>;
17+
type TNopeFoo = typeof foo<?string>;
18+
type TComeOnFoo = typeof foo<?string?>;
19+
20+
const WhatBar = Bar<?>;
21+
const HuhBar = Bar<string?>;
22+
const NopeBar = Bar<?string>;
23+
const ComeOnBar = Bar<?string?>;
24+
25+
type TWhatBar = typeof Bar<?>;
26+
type THuhBar = typeof Bar<string?>;
27+
type TNopeBar = typeof Bar<?string>;
28+
type TComeOnBar = typeof Bar<?string?>;
29+
30+
31+
//// [expressionWithJSDocTypeArguments.js]
32+
"use strict";
33+
// Repro from #51802
34+
function foo(x) { return x; }
35+
var Bar = /** @class */ (function () {
36+
function Bar(x) {
37+
this.x = x;
38+
}
39+
return Bar;
40+
}());
41+
// Errors expected on all of the following
42+
var WhatFoo = foo<?>;
43+
var HuhFoo = foo<?string>;
44+
var NopeFoo = foo<?string>;
45+
var ComeOnFoo = foo<??string>;
46+
var WhatBar = Bar<?>;
47+
var HuhBar = Bar<?string>;
48+
var NopeBar = Bar<?string>;
49+
var ComeOnBar = Bar<??string>;
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
=== tests/cases/compiler/expressionWithJSDocTypeArguments.ts ===
2+
// Repro from #51802
3+
4+
function foo<T>(x: T): T { return x }
5+
>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0))
6+
>T : Symbol(T, Decl(expressionWithJSDocTypeArguments.ts, 2, 13))
7+
>x : Symbol(x, Decl(expressionWithJSDocTypeArguments.ts, 2, 16))
8+
>T : Symbol(T, Decl(expressionWithJSDocTypeArguments.ts, 2, 13))
9+
>T : Symbol(T, Decl(expressionWithJSDocTypeArguments.ts, 2, 13))
10+
>x : Symbol(x, Decl(expressionWithJSDocTypeArguments.ts, 2, 16))
11+
12+
class Bar<T> { constructor(public x: T) { } }
13+
>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37))
14+
>T : Symbol(T, Decl(expressionWithJSDocTypeArguments.ts, 4, 10))
15+
>x : Symbol(Bar.x, Decl(expressionWithJSDocTypeArguments.ts, 4, 27))
16+
>T : Symbol(T, Decl(expressionWithJSDocTypeArguments.ts, 4, 10))
17+
18+
// Errors expected on all of the following
19+
20+
const WhatFoo = foo<?>;
21+
>WhatFoo : Symbol(WhatFoo, Decl(expressionWithJSDocTypeArguments.ts, 8, 5))
22+
>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0))
23+
24+
const HuhFoo = foo<string?>;
25+
>HuhFoo : Symbol(HuhFoo, Decl(expressionWithJSDocTypeArguments.ts, 9, 5))
26+
>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0))
27+
28+
const NopeFoo = foo<?string>;
29+
>NopeFoo : Symbol(NopeFoo, Decl(expressionWithJSDocTypeArguments.ts, 10, 5))
30+
>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0))
31+
32+
const ComeOnFoo = foo<?string?>;
33+
>ComeOnFoo : Symbol(ComeOnFoo, Decl(expressionWithJSDocTypeArguments.ts, 11, 5))
34+
>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0))
35+
36+
type TWhatFoo = typeof foo<?>;
37+
>TWhatFoo : Symbol(TWhatFoo, Decl(expressionWithJSDocTypeArguments.ts, 11, 32))
38+
>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0))
39+
40+
type THuhFoo = typeof foo<string?>;
41+
>THuhFoo : Symbol(THuhFoo, Decl(expressionWithJSDocTypeArguments.ts, 13, 30))
42+
>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0))
43+
44+
type TNopeFoo = typeof foo<?string>;
45+
>TNopeFoo : Symbol(TNopeFoo, Decl(expressionWithJSDocTypeArguments.ts, 14, 35))
46+
>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0))
47+
48+
type TComeOnFoo = typeof foo<?string?>;
49+
>TComeOnFoo : Symbol(TComeOnFoo, Decl(expressionWithJSDocTypeArguments.ts, 15, 36))
50+
>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0))
51+
52+
const WhatBar = Bar<?>;
53+
>WhatBar : Symbol(WhatBar, Decl(expressionWithJSDocTypeArguments.ts, 18, 5))
54+
>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37))
55+
56+
const HuhBar = Bar<string?>;
57+
>HuhBar : Symbol(HuhBar, Decl(expressionWithJSDocTypeArguments.ts, 19, 5))
58+
>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37))
59+
60+
const NopeBar = Bar<?string>;
61+
>NopeBar : Symbol(NopeBar, Decl(expressionWithJSDocTypeArguments.ts, 20, 5))
62+
>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37))
63+
64+
const ComeOnBar = Bar<?string?>;
65+
>ComeOnBar : Symbol(ComeOnBar, Decl(expressionWithJSDocTypeArguments.ts, 21, 5))
66+
>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37))
67+
68+
type TWhatBar = typeof Bar<?>;
69+
>TWhatBar : Symbol(TWhatBar, Decl(expressionWithJSDocTypeArguments.ts, 21, 32))
70+
>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37))
71+
72+
type THuhBar = typeof Bar<string?>;
73+
>THuhBar : Symbol(THuhBar, Decl(expressionWithJSDocTypeArguments.ts, 23, 30))
74+
>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37))
75+
76+
type TNopeBar = typeof Bar<?string>;
77+
>TNopeBar : Symbol(TNopeBar, Decl(expressionWithJSDocTypeArguments.ts, 24, 35))
78+
>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37))
79+
80+
type TComeOnBar = typeof Bar<?string?>;
81+
>TComeOnBar : Symbol(TComeOnBar, Decl(expressionWithJSDocTypeArguments.ts, 25, 36))
82+
>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37))
83+
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
=== tests/cases/compiler/expressionWithJSDocTypeArguments.ts ===
2+
// Repro from #51802
3+
4+
function foo<T>(x: T): T { return x }
5+
>foo : <T>(x: T) => T
6+
>x : T
7+
>x : T
8+
9+
class Bar<T> { constructor(public x: T) { } }
10+
>Bar : Bar<T>
11+
>x : T
12+
13+
// Errors expected on all of the following
14+
15+
const WhatFoo = foo<?>;
16+
>WhatFoo : (x: any) => any
17+
>foo<?> : (x: any) => any
18+
>foo : <T>(x: T) => T
19+
20+
const HuhFoo = foo<string?>;
21+
>HuhFoo : (x: string | null) => string | null
22+
>foo<string?> : (x: string | null) => string | null
23+
>foo : <T>(x: T) => T
24+
25+
const NopeFoo = foo<?string>;
26+
>NopeFoo : (x: string | null) => string | null
27+
>foo<?string> : (x: string | null) => string | null
28+
>foo : <T>(x: T) => T
29+
30+
const ComeOnFoo = foo<?string?>;
31+
>ComeOnFoo : (x: string | null) => string | null
32+
>foo<?string?> : (x: string | null) => string | null
33+
>foo : <T>(x: T) => T
34+
35+
type TWhatFoo = typeof foo<?>;
36+
>TWhatFoo : (x: any) => any
37+
>foo : <T>(x: T) => T
38+
39+
type THuhFoo = typeof foo<string?>;
40+
>THuhFoo : (x: string | null) => string | null
41+
>foo : <T>(x: T) => T
42+
43+
type TNopeFoo = typeof foo<?string>;
44+
>TNopeFoo : (x: string | null) => string | null
45+
>foo : <T>(x: T) => T
46+
47+
type TComeOnFoo = typeof foo<?string?>;
48+
>TComeOnFoo : (x: string | null) => string | null
49+
>foo : <T>(x: T) => T
50+
51+
const WhatBar = Bar<?>;
52+
>WhatBar : { new (x: any): Bar<any>; prototype: Bar<any>; }
53+
>Bar<?> : { new (x: any): Bar<any>; prototype: Bar<any>; }
54+
>Bar : typeof Bar
55+
56+
const HuhBar = Bar<string?>;
57+
>HuhBar : { new (x: string | null): Bar<string | null>; prototype: Bar<any>; }
58+
>Bar<string?> : { new (x: string | null): Bar<string | null>; prototype: Bar<any>; }
59+
>Bar : typeof Bar
60+
61+
const NopeBar = Bar<?string>;
62+
>NopeBar : { new (x: string | null): Bar<string | null>; prototype: Bar<any>; }
63+
>Bar<?string> : { new (x: string | null): Bar<string | null>; prototype: Bar<any>; }
64+
>Bar : typeof Bar
65+
66+
const ComeOnBar = Bar<?string?>;
67+
>ComeOnBar : { new (x: string | null): Bar<string | null>; prototype: Bar<any>; }
68+
>Bar<?string?> : { new (x: string | null): Bar<string | null>; prototype: Bar<any>; }
69+
>Bar : typeof Bar
70+
71+
type TWhatBar = typeof Bar<?>;
72+
>TWhatBar : { new (x: any): Bar<any>; prototype: Bar<any>; }
73+
>Bar : typeof Bar
74+
75+
type THuhBar = typeof Bar<string?>;
76+
>THuhBar : { new (x: string | null): Bar<string | null>; prototype: Bar<any>; }
77+
>Bar : typeof Bar
78+
79+
type TNopeBar = typeof Bar<?string>;
80+
>TNopeBar : { new (x: string | null): Bar<string | null>; prototype: Bar<any>; }
81+
>Bar : typeof Bar
82+
83+
type TComeOnBar = typeof Bar<?string?>;
84+
>TComeOnBar : { new (x: string | null): Bar<string | null>; prototype: Bar<any>; }
85+
>Bar : typeof Bar
86+

tests/baselines/reference/importWithTypeArguments.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
tests/cases/conformance/types/import/importWithTypeArguments.ts(1,1): error TS1326: This use of 'import' is invalid. 'import()' calls can be written, but they must have parentheses and cannot have type arguments.
2+
tests/cases/conformance/types/import/importWithTypeArguments.ts(1,8): error TS2304: Cannot find name 'T'.
23
tests/cases/conformance/types/import/importWithTypeArguments.ts(2,11): error TS1326: This use of 'import' is invalid. 'import()' calls can be written, but they must have parentheses and cannot have type arguments.
34

45

5-
==== tests/cases/conformance/types/import/importWithTypeArguments.ts (2 errors) ====
6+
==== tests/cases/conformance/types/import/importWithTypeArguments.ts (3 errors) ====
67
import<T>
78
~~~~~~~~~
89
!!! error TS1326: This use of 'import' is invalid. 'import()' calls can be written, but they must have parentheses and cannot have type arguments.
10+
~
11+
!!! error TS2304: Cannot find name 'T'.
912
const a = import<string, number>
1013
~~~~~~~~~~~~~~~~~~~~~~
1114
!!! error TS1326: This use of 'import' is invalid. 'import()' calls can be written, but they must have parentheses and cannot have type arguments.

tests/baselines/reference/parserMemberAccessExpression1.errors.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression
44
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(2,9): error TS2304: Cannot find name 'T'.
55
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(3,1): error TS2304: Cannot find name 'Foo'.
66
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(3,4): error TS1477: An instantiation expression cannot be followed by a property access.
7+
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(3,5): error TS2304: Cannot find name 'T'.
78
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,1): error TS2304: Cannot find name 'Foo'.
89
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,4): error TS1477: An instantiation expression cannot be followed by a property access.
10+
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,5): error TS2304: Cannot find name 'T'.
911
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,12): error TS2304: Cannot find name 'T'.
1012

1113

12-
==== tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts (9 errors) ====
14+
==== tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts (11 errors) ====
1315
Foo<T>();
1416
~~~
1517
!!! error TS2304: Cannot find name 'Foo'.
@@ -25,11 +27,15 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression
2527
!!! error TS2304: Cannot find name 'Foo'.
2628
~~~
2729
!!! error TS1477: An instantiation expression cannot be followed by a property access.
30+
~
31+
!!! error TS2304: Cannot find name 'T'.
2832
Foo<T>.Bar<T>();
2933
~~~
3034
!!! error TS2304: Cannot find name 'Foo'.
3135
~~~
3236
!!! error TS1477: An instantiation expression cannot be followed by a property access.
37+
~
38+
!!! error TS2304: Cannot find name 'T'.
3339
~
3440
!!! error TS2304: Cannot find name 'T'.
3541

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
tests/cases/conformance/parser/ecmascript5/Types/parserTypeQuery8.ts(1,15): error TS2304: Cannot find name 'A'.
2+
tests/cases/conformance/parser/ecmascript5/Types/parserTypeQuery8.ts(1,17): error TS2304: Cannot find name 'B'.
23

34

4-
==== tests/cases/conformance/parser/ecmascript5/Types/parserTypeQuery8.ts (1 errors) ====
5+
==== tests/cases/conformance/parser/ecmascript5/Types/parserTypeQuery8.ts (2 errors) ====
56
var v: typeof A<B>
67
~
7-
!!! error TS2304: Cannot find name 'A'.
8+
!!! error TS2304: Cannot find name 'A'.
9+
~
10+
!!! error TS2304: Cannot find name 'B'.

0 commit comments

Comments
 (0)