Skip to content

Commit da5eb1a

Browse files
committed
Move error to type argument range
1 parent 2925fcf commit da5eb1a

7 files changed

+22
-17
lines changed

src/compiler/parser.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5646,8 +5646,10 @@ namespace ts {
56465646
if (isOptionalChain && isPrivateIdentifier(propertyAccess.name)) {
56475647
parseErrorAtRange(propertyAccess.name, Diagnostics.An_optional_chain_cannot_contain_private_identifiers);
56485648
}
5649-
else if (isExpressionWithTypeArguments(expression)) {
5650-
parseErrorAtRange(propertyAccess.name, Diagnostics.Instantiation_expression_cannot_be_followed_by_property_access);
5649+
if (isExpressionWithTypeArguments(expression) && expression.typeArguments) {
5650+
const pos = expression.typeArguments.pos - 1;
5651+
const end = skipTrivia(sourceText, expression.typeArguments.end) + 1;
5652+
parseErrorAt(pos, end, Diagnostics.Instantiation_expression_cannot_be_followed_by_property_access);
56515653
}
56525654
return finishNode(propertyAccess, pos);
56535655
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
tests/cases/compiler/genericCallWithoutArgs.ts(4,2): error TS1477: Instantiation expression cannot be followed by property access.
12
tests/cases/compiler/genericCallWithoutArgs.ts(4,18): error TS1003: Identifier expected.
23

34

4-
==== tests/cases/compiler/genericCallWithoutArgs.ts (1 errors) ====
5+
==== tests/cases/compiler/genericCallWithoutArgs.ts (2 errors) ====
56
function f<X, Y>(x: X, y: Y) {
67
}
78

89
f<number,string>.
10+
~~~~~~~~~~~~~~~
11+
!!! error TS1477: Instantiation expression cannot be followed by property access.
912

1013
!!! error TS1003: Identifier expected.

tests/baselines/reference/instantiationExpressionErrors.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(7,22): error TS1477: Instantiation expression cannot be followed by property access.
2-
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(8,22): error TS1477: Instantiation expression cannot be followed by property access.
1+
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(7,13): error TS1477: Instantiation expression cannot be followed by property access.
2+
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(8,13): error TS1477: Instantiation expression cannot be followed by property access.
33
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(13,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'string[]'.
44
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.
55
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(18,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'.
@@ -24,10 +24,10 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpr
2424
const a1 = f<number>; // { (): number; g<U>(): U; }
2525
const a2 = f.g<number>; // () => number
2626
const a3 = f<number>.g; // <U>() => U
27-
~
27+
~~~~~~~~
2828
!!! error TS1477: Instantiation expression cannot be followed by property access.
2929
const a4 = f<number>.g<number>; // () => number
30-
~
30+
~~~~~~~~
3131
!!! error TS1477: Instantiation expression cannot be followed by property access.
3232
const a5 = f['g']<number>; // () => number
3333

tests/baselines/reference/optionalChainWithInstantiationExpression1(target=es2019).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/optionalChainWithInstantiationExpression1.ts(12,9): error TS1477: Instantiation expression cannot be followed by property access.
1+
tests/cases/compiler/optionalChainWithInstantiationExpression1.ts(12,5): error TS1477: Instantiation expression cannot be followed by property access.
22

33

44
==== tests/cases/compiler/optionalChainWithInstantiationExpression1.ts (1 errors) ====
@@ -14,7 +14,7 @@ tests/cases/compiler/optionalChainWithInstantiationExpression1.ts(12,9): error T
1414
declare const a: typeof A | undefined;
1515

1616
a?.b<c>.d;
17-
~
17+
~~~
1818
!!! error TS1477: Instantiation expression cannot be followed by property access.
1919

2020
a?.b.d

tests/baselines/reference/optionalChainWithInstantiationExpression1(target=es2020).errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/optionalChainWithInstantiationExpression1.ts(12,9): error TS1477: Instantiation expression cannot be followed by property access.
1+
tests/cases/compiler/optionalChainWithInstantiationExpression1.ts(12,5): error TS1477: Instantiation expression cannot be followed by property access.
22

33

44
==== tests/cases/compiler/optionalChainWithInstantiationExpression1.ts (1 errors) ====
@@ -14,7 +14,7 @@ tests/cases/compiler/optionalChainWithInstantiationExpression1.ts(12,9): error T
1414
declare const a: typeof A | undefined;
1515

1616
a?.b<c>.d;
17-
~
17+
~~~
1818
!!! error TS1477: Instantiation expression cannot be followed by property access.
1919

2020
a?.b.d

tests/baselines/reference/parserMemberAccessExpression1.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression
33
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(2,1): error TS2304: Cannot find name 'Foo'.
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'.
6-
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(3,8): error TS1477: Instantiation expression cannot be followed by property access.
6+
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(3,4): error TS1477: Instantiation expression cannot be followed by property access.
77
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,1): error TS2304: Cannot find name 'Foo'.
8-
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,8): error TS1477: Instantiation expression cannot be followed by property access.
8+
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,4): error TS1477: Instantiation expression cannot be followed by property access.
99
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,12): error TS2304: Cannot find name 'T'.
1010

1111

@@ -23,12 +23,12 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression
2323
Foo<T>.Bar();
2424
~~~
2525
!!! error TS2304: Cannot find name 'Foo'.
26-
~~~
26+
~~~
2727
!!! error TS1477: Instantiation expression cannot be followed by property access.
2828
Foo<T>.Bar<T>();
2929
~~~
3030
!!! error TS2304: Cannot find name 'Foo'.
31-
~~~
31+
~~~
3232
!!! error TS1477: Instantiation expression cannot be followed by property access.
3333
~
3434
!!! error TS2304: Cannot find name 'T'.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessOffOfGenericType1.ts(1,9): error TS2304: Cannot find name 'List'.
2-
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessOffOfGenericType1.ts(1,22): error TS1477: Instantiation expression cannot be followed by property access.
2+
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessOffOfGenericType1.ts(1,13): error TS1477: Instantiation expression cannot be followed by property access.
33

44

55
==== tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessOffOfGenericType1.ts (2 errors) ====
66
var v = List<number>.makeChild();
77
~~~~
88
!!! error TS2304: Cannot find name 'List'.
9-
~~~~~~~~~
9+
~~~~~~~~
1010
!!! error TS1477: Instantiation expression cannot be followed by property access.

0 commit comments

Comments
 (0)