Skip to content

Commit

Permalink
Move error to type argument range
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Jun 24, 2022
1 parent 2925fcf commit da5eb1a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5646,8 +5646,10 @@ namespace ts {
if (isOptionalChain && isPrivateIdentifier(propertyAccess.name)) {
parseErrorAtRange(propertyAccess.name, Diagnostics.An_optional_chain_cannot_contain_private_identifiers);
}
else if (isExpressionWithTypeArguments(expression)) {
parseErrorAtRange(propertyAccess.name, Diagnostics.Instantiation_expression_cannot_be_followed_by_property_access);
if (isExpressionWithTypeArguments(expression) && expression.typeArguments) {
const pos = expression.typeArguments.pos - 1;
const end = skipTrivia(sourceText, expression.typeArguments.end) + 1;
parseErrorAt(pos, end, Diagnostics.Instantiation_expression_cannot_be_followed_by_property_access);
}
return finishNode(propertyAccess, pos);
}
Expand Down
5 changes: 4 additions & 1 deletion tests/baselines/reference/genericCallWithoutArgs.errors.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
tests/cases/compiler/genericCallWithoutArgs.ts(4,2): error TS1477: Instantiation expression cannot be followed by property access.
tests/cases/compiler/genericCallWithoutArgs.ts(4,18): error TS1003: Identifier expected.


==== tests/cases/compiler/genericCallWithoutArgs.ts (1 errors) ====
==== tests/cases/compiler/genericCallWithoutArgs.ts (2 errors) ====
function f<X, Y>(x: X, y: Y) {
}

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

!!! error TS1003: Identifier expected.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(7,22): error TS1477: Instantiation expression cannot be followed by property access.
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(8,22): error TS1477: Instantiation expression cannot be followed by property access.
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(7,13): error TS1477: Instantiation expression cannot be followed by property access.
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(8,13): error TS1477: Instantiation expression cannot be followed by property access.
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(13,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'string[]'.
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.
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressionErrors.ts(18,12): error TS2365: Operator '>' cannot be applied to types 'boolean' and 'number'.
Expand All @@ -24,10 +24,10 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpr
const a1 = f<number>; // { (): number; g<U>(): U; }
const a2 = f.g<number>; // () => number
const a3 = f<number>.g; // <U>() => U
~
~~~~~~~~
!!! error TS1477: Instantiation expression cannot be followed by property access.
const a4 = f<number>.g<number>; // () => number
~
~~~~~~~~
!!! error TS1477: Instantiation expression cannot be followed by property access.
const a5 = f['g']<number>; // () => number

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/optionalChainWithInstantiationExpression1.ts(12,9): error TS1477: Instantiation expression cannot be followed by property access.
tests/cases/compiler/optionalChainWithInstantiationExpression1.ts(12,5): error TS1477: Instantiation expression cannot be followed by property access.


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

a?.b<c>.d;
~
~~~
!!! error TS1477: Instantiation expression cannot be followed by property access.

a?.b.d
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tests/cases/compiler/optionalChainWithInstantiationExpression1.ts(12,9): error TS1477: Instantiation expression cannot be followed by property access.
tests/cases/compiler/optionalChainWithInstantiationExpression1.ts(12,5): error TS1477: Instantiation expression cannot be followed by property access.


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

a?.b<c>.d;
~
~~~
!!! error TS1477: Instantiation expression cannot be followed by property access.

a?.b.d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(2,1): error TS2304: Cannot find name 'Foo'.
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(2,9): error TS2304: Cannot find name 'T'.
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(3,1): error TS2304: Cannot find name 'Foo'.
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(3,8): error TS1477: Instantiation expression cannot be followed by property access.
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(3,4): error TS1477: Instantiation expression cannot be followed by property access.
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,1): error TS2304: Cannot find name 'Foo'.
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,8): error TS1477: Instantiation expression cannot be followed by property access.
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,4): error TS1477: Instantiation expression cannot be followed by property access.
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,12): error TS2304: Cannot find name 'T'.


Expand All @@ -23,12 +23,12 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression
Foo<T>.Bar();
~~~
!!! error TS2304: Cannot find name 'Foo'.
~~~
~~~
!!! error TS1477: Instantiation expression cannot be followed by property access.
Foo<T>.Bar<T>();
~~~
!!! error TS2304: Cannot find name 'Foo'.
~~~
~~~
!!! error TS1477: Instantiation expression cannot be followed by property access.
~
!!! error TS2304: Cannot find name 'T'.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessOffOfGenericType1.ts(1,9): error TS2304: Cannot find name 'List'.
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessOffOfGenericType1.ts(1,22): error TS1477: Instantiation expression cannot be followed by property access.
tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessOffOfGenericType1.ts(1,13): error TS1477: Instantiation expression cannot be followed by property access.


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

0 comments on commit da5eb1a

Please sign in to comment.