Skip to content

Commit 728c9b4

Browse files
committed
Create diagnostics, move to checker grammar check
1 parent 7357548 commit 728c9b4

25 files changed

+91
-128
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28912,7 +28912,14 @@ namespace ts {
2891228912
return nonNullType;
2891328913
}
2891428914

28915+
function checkGrammarPropertyAccessExpression(node: PropertyAccessExpression) {
28916+
if (node.expression.kind === SyntaxKind.ExpressionWithTypeArguments) {
28917+
grammarErrorOnNode(node.name, Diagnostics.Instantiation_expression_cannot_be_followed_by_property_access);
28918+
}
28919+
}
28920+
2891528921
function checkPropertyAccessExpression(node: PropertyAccessExpression, checkMode: CheckMode | undefined) {
28922+
checkGrammarPropertyAccessExpression(node);
2891628923
return node.flags & NodeFlags.OptionalChain ? checkPropertyAccessChain(node as PropertyAccessChain, checkMode) :
2891728924
checkPropertyAccessExpressionOrQualifiedName(node, node.expression, checkNonNullExpression(node.expression), node.name, checkMode);
2891828925
}

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,10 @@
14931493
"category": "Message",
14941494
"code": 1476
14951495
},
1496+
"Instantiation expression cannot be followed by property access.": {
1497+
"category": "Error",
1498+
"code": 1477
1499+
},
14961500

14971501
"The types of '{0}' are incompatible between these types.": {
14981502
"category": "Error",

src/compiler/parser.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5683,10 +5683,6 @@ namespace ts {
56835683
}
56845684

56855685
if (isPropertyAccess) {
5686-
// TODO: issue a better error?
5687-
if (expression.kind === SyntaxKind.ExpressionWithTypeArguments) {
5688-
return expression as MemberExpression;
5689-
}
56905686
expression = parsePropertyAccessExpressionRest(pos, expression, questionDotToken);
56915687
continue;
56925688
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tests/cases/compiler/genericCallWithoutArgs.ts(4,18): error TS1003: Identifier expected.
2+
3+
4+
==== tests/cases/compiler/genericCallWithoutArgs.ts (1 errors) ====
5+
function f<X, Y>(x: X, y: Y) {
6+
}
7+
8+
f<number,string>.
9+
10+
!!! error TS1003: Identifier expected.

tests/baselines/reference/genericCallWithoutArgs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ f<number,string>.
77
//// [genericCallWithoutArgs.js]
88
function f(x, y) {
99
}
10-
f;
10+
f.;

tests/baselines/reference/genericCallWithoutArgs.types

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ function f<X, Y>(x: X, y: Y) {
66
}
77

88
f<number,string>.
9+
>f<number,string>. : any
910
>f<number,string> : (x: number, y: string) => void
1011
>f : <X, Y>(x: X, y: Y) => void
12+
> : any
1113

tests/baselines/reference/instantiationExpressionErrors.errors.txt

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(7,22): error TS1005: ',' expected.
2-
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(7,22): error TS2451: Cannot redeclare block-scoped variable 'g'.
3-
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(7,22): error TS7005: Variable 'g' implicitly has an 'any' type.
4-
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(8,22): error TS1005: ',' expected.
5-
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(8,22): error TS2451: Cannot redeclare block-scoped variable 'g'.
6-
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(8,22): error TS7005: Variable 'g' implicitly has an 'any' type.
7-
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(8,23): error TS1005: ',' expected.
8-
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(8,31): error TS1109: Expression expected.
91
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(13,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'string[]'.
102
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(13,14): error TS2693: 'number' only refers to a type, but is being used as a value here.
113
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(18,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'.
@@ -14,10 +6,6 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpr
146
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(19,24): error TS2635: Type '{ (): number; g<U>(): U; }' has no signatures for which the type argument list is applicable.
157
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(23,23): error TS1005: '(' expected.
168
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(26,24): error TS2558: Expected 0 type arguments, but got 1.
17-
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(30,13): error TS2451: Cannot redeclare block-scoped variable 'g'.
18-
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(32,14): error TS2635: Type 'any' has no signatures for which the type argument list is applicable.
19-
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(33,14): error TS2635: Type 'any' has no signatures for which the type argument list is applicable.
20-
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(34,14): error TS2635: Type 'any' has no signatures for which the type argument list is applicable.
219
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(39,2): error TS2554: Expected 0 arguments, but got 1.
2210
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(43,12): error TS2365: Operator '<' cannot be applied to types '{ <T>(): T; g<U>(): U; }' and 'boolean'.
2311
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(44,12): error TS2365: Operator '<' cannot be applied to types '{ <T>(): T; g<U>(): U; }' and 'boolean'.
@@ -26,31 +14,15 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpr
2614
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(45,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'.
2715

2816

29-
==== tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts (26 errors) ====
17+
==== tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts (14 errors) ====
3018
declare let f: { <T>(): T, g<U>(): U };
3119

3220
// Type arguments in member expressions
3321

3422
const a1 = f<number>; // { (): number; g<U>(): U; }
3523
const a2 = f.g<number>; // () => number
3624
const a3 = f<number>.g; // <U>() => U
37-
~
38-
!!! error TS1005: ',' expected.
39-
~
40-
!!! error TS2451: Cannot redeclare block-scoped variable 'g'.
41-
~
42-
!!! error TS7005: Variable 'g' implicitly has an 'any' type.
4325
const a4 = f<number>.g<number>; // () => number
44-
~
45-
!!! error TS1005: ',' expected.
46-
~
47-
!!! error TS2451: Cannot redeclare block-scoped variable 'g'.
48-
~
49-
!!! error TS7005: Variable 'g' implicitly has an 'any' type.
50-
~
51-
!!! error TS1005: ',' expected.
52-
~
53-
!!! error TS1109: Expression expected.
5426
const a5 = f['g']<number>; // () => number
5527

5628
// `[` is an expression starter and cannot immediately follow a type argument list
@@ -89,18 +61,10 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpr
8961
// Instantiation expression and binary operators
9062

9163
declare let g: (<T>(x: T) => T) | undefined;
92-
~
93-
!!! error TS2451: Cannot redeclare block-scoped variable 'g'.
9464

9565
const c1 = g<string> || ((x: string) => x);
96-
~~~~~~
97-
!!! error TS2635: Type 'any' has no signatures for which the type argument list is applicable.
9866
const c2 = g<string> ?? ((x: string) => x);
99-
~~~~~~
100-
!!! error TS2635: Type 'any' has no signatures for which the type argument list is applicable.
10167
const c3 = g<string> && ((x: string) => x);
102-
~~~~~~
103-
!!! error TS2635: Type 'any' has no signatures for which the type argument list is applicable.
10468

10569
// Parsed as function call, even though this differs from JavaScript
10670

tests/baselines/reference/instantiationExpressionErrors.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ var _a, _b, _c;
110110
// Type arguments in member expressions
111111
var a1 = (f); // { (): number; g<U>(): U; }
112112
var a2 = (f.g); // () => number
113-
var a3 = (f), g; // <U>() => U
114-
var a4 = (f), g;
115-
; // () => number
113+
var a3 = f.g; // <U>() => U
114+
var a4 = (f.g); // () => number
116115
var a5 = (f['g']); // () => number
117116
// `[` is an expression starter and cannot immediately follow a type argument list
118117
var a6 = f < number > ['g']; // Error
@@ -200,14 +199,8 @@ declare const a1: {
200199
g<U>(): U;
201200
};
202201
declare const a2: () => number;
203-
declare const a3: {
204-
(): number;
205-
g<U>(): U;
206-
}, g: any;
207-
declare const a4: {
208-
(): number;
209-
g<U>(): U;
210-
}, g: any;
202+
declare const a3: <U>() => U;
203+
declare const a4: () => number;
211204
declare const a5: () => number;
212205
declare const a6: boolean;
213206
declare const a7: <U>() => U;
@@ -220,9 +213,9 @@ declare const b2: number;
220213
declare const b3: number;
221214
declare const b4: number;
222215
declare let g: (<T>(x: T) => T) | undefined;
223-
declare const c1: any;
224-
declare const c2: any;
225-
declare const c3: any;
216+
declare const c1: (x: string) => string;
217+
declare const c2: (x: string) => string;
218+
declare const c3: ((x: string) => string) | undefined;
226219
declare const x1: true;
227220
declare const r1: boolean;
228221
declare const r2: boolean;

tests/baselines/reference/instantiationExpressionErrors.symbols

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ const a2 = f.g<number>; // () => number
2121

2222
const a3 = f<number>.g; // <U>() => U
2323
>a3 : Symbol(a3, Decl(instantiationExpressionErrors.ts, 6, 5))
24+
>f<number>.g : Symbol(g, Decl(instantiationExpressionErrors.ts, 0, 26))
2425
>f : Symbol(f, Decl(instantiationExpressionErrors.ts, 0, 11))
25-
>g : Symbol(g, Decl(instantiationExpressionErrors.ts, 6, 21))
26+
>g : Symbol(g, Decl(instantiationExpressionErrors.ts, 0, 26))
2627

2728
const a4 = f<number>.g<number>; // () => number
2829
>a4 : Symbol(a4, Decl(instantiationExpressionErrors.ts, 7, 5))
30+
>f<number>.g : Symbol(g, Decl(instantiationExpressionErrors.ts, 0, 26))
2931
>f : Symbol(f, Decl(instantiationExpressionErrors.ts, 0, 11))
30-
>g : Symbol(g, Decl(instantiationExpressionErrors.ts, 7, 21))
32+
>g : Symbol(g, Decl(instantiationExpressionErrors.ts, 0, 26))
3133

3234
const a5 = f['g']<number>; // () => number
3335
>a5 : Symbol(a5, Decl(instantiationExpressionErrors.ts, 8, 5))
@@ -84,19 +86,19 @@ declare let g: (<T>(x: T) => T) | undefined;
8486

8587
const c1 = g<string> || ((x: string) => x);
8688
>c1 : Symbol(c1, Decl(instantiationExpressionErrors.ts, 31, 5))
87-
>g : Symbol(g, Decl(instantiationExpressionErrors.ts, 6, 21))
89+
>g : Symbol(g, Decl(instantiationExpressionErrors.ts, 29, 11))
8890
>x : Symbol(x, Decl(instantiationExpressionErrors.ts, 31, 26))
8991
>x : Symbol(x, Decl(instantiationExpressionErrors.ts, 31, 26))
9092

9193
const c2 = g<string> ?? ((x: string) => x);
9294
>c2 : Symbol(c2, Decl(instantiationExpressionErrors.ts, 32, 5))
93-
>g : Symbol(g, Decl(instantiationExpressionErrors.ts, 6, 21))
95+
>g : Symbol(g, Decl(instantiationExpressionErrors.ts, 29, 11))
9496
>x : Symbol(x, Decl(instantiationExpressionErrors.ts, 32, 26))
9597
>x : Symbol(x, Decl(instantiationExpressionErrors.ts, 32, 26))
9698

9799
const c3 = g<string> && ((x: string) => x);
98100
>c3 : Symbol(c3, Decl(instantiationExpressionErrors.ts, 33, 5))
99-
>g : Symbol(g, Decl(instantiationExpressionErrors.ts, 6, 21))
101+
>g : Symbol(g, Decl(instantiationExpressionErrors.ts, 29, 11))
100102
>x : Symbol(x, Decl(instantiationExpressionErrors.ts, 33, 26))
101103
>x : Symbol(x, Decl(instantiationExpressionErrors.ts, 33, 26))
102104

tests/baselines/reference/instantiationExpressionErrors.types

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,19 @@ const a2 = f.g<number>; // () => number
1818
>g : <U>() => U
1919

2020
const a3 = f<number>.g; // <U>() => U
21-
>a3 : { (): number; g<U>(): U; }
21+
>a3 : <U>() => U
22+
>f<number>.g : <U>() => U
2223
>f<number> : { (): number; g<U>(): U; }
2324
>f : { <T>(): T; g<U>(): U; }
24-
>g : any
25+
>g : <U>() => U
2526

2627
const a4 = f<number>.g<number>; // () => number
27-
>a4 : { (): number; g<U>(): U; }
28+
>a4 : () => number
29+
>f<number>.g<number> : () => number
30+
>f<number>.g : <U>() => U
2831
>f<number> : { (): number; g<U>(): U; }
2932
>f : { <T>(): T; g<U>(): U; }
30-
>g : any
31-
><number> : number
32-
> : any
33+
>g : <U>() => U
3334

3435
const a5 = f['g']<number>; // () => number
3536
>a5 : () => number
@@ -106,30 +107,30 @@ declare let g: (<T>(x: T) => T) | undefined;
106107
>x : T
107108

108109
const c1 = g<string> || ((x: string) => x);
109-
>c1 : any
110-
>g<string> || ((x: string) => x) : any
111-
>g<string> : any
112-
>g : any
110+
>c1 : (x: string) => string
111+
>g<string> || ((x: string) => x) : (x: string) => string
112+
>g<string> : ((x: string) => string) | undefined
113+
>g : (<T>(x: T) => T) | undefined
113114
>((x: string) => x) : (x: string) => string
114115
>(x: string) => x : (x: string) => string
115116
>x : string
116117
>x : string
117118

118119
const c2 = g<string> ?? ((x: string) => x);
119-
>c2 : any
120-
>g<string> ?? ((x: string) => x) : any
121-
>g<string> : any
122-
>g : any
120+
>c2 : (x: string) => string
121+
>g<string> ?? ((x: string) => x) : (x: string) => string
122+
>g<string> : ((x: string) => string) | undefined
123+
>g : (<T>(x: T) => T) | undefined
123124
>((x: string) => x) : (x: string) => string
124125
>(x: string) => x : (x: string) => string
125126
>x : string
126127
>x : string
127128

128129
const c3 = g<string> && ((x: string) => x);
129-
>c3 : any
130-
>g<string> && ((x: string) => x) : any
131-
>g<string> : any
132-
>g : any
130+
>c3 : ((x: string) => string) | undefined
131+
>g<string> && ((x: string) => x) : ((x: string) => string) | undefined
132+
>g<string> : ((x: string) => string) | undefined
133+
>g : (<T>(x: T) => T) | undefined
133134
>((x: string) => x) : (x: string) => string
134135
>(x: string) => x : (x: string) => string
135136
>x : string

0 commit comments

Comments
 (0)