From da5eb1a62fcf1f44b2b5befe5c555f27bdbc4ceb Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 24 Jun 2022 13:08:27 -0700 Subject: [PATCH] Move error to type argument range --- src/compiler/parser.ts | 6 ++++-- .../baselines/reference/genericCallWithoutArgs.errors.txt | 5 ++++- .../reference/instantiationExpressionErrors.errors.txt | 8 ++++---- ...WithInstantiationExpression1(target=es2019).errors.txt | 4 ++-- ...WithInstantiationExpression1(target=es2020).errors.txt | 4 ++-- .../reference/parserMemberAccessExpression1.errors.txt | 8 ++++---- .../parserMemberAccessOffOfGenericType1.errors.txt | 4 ++-- 7 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7fad8d856a51a..05118ac339431 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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); } diff --git a/tests/baselines/reference/genericCallWithoutArgs.errors.txt b/tests/baselines/reference/genericCallWithoutArgs.errors.txt index 75a2d51a1da3e..f44750e805de3 100644 --- a/tests/baselines/reference/genericCallWithoutArgs.errors.txt +++ b/tests/baselines/reference/genericCallWithoutArgs.errors.txt @@ -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: X, y: Y) { } f. + ~~~~~~~~~~~~~~~ +!!! error TS1477: Instantiation expression cannot be followed by property access. !!! error TS1003: Identifier expected. \ No newline at end of file diff --git a/tests/baselines/reference/instantiationExpressionErrors.errors.txt b/tests/baselines/reference/instantiationExpressionErrors.errors.txt index 1c51d967e568f..ccfc5c4077e21 100644 --- a/tests/baselines/reference/instantiationExpressionErrors.errors.txt +++ b/tests/baselines/reference/instantiationExpressionErrors.errors.txt @@ -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'. @@ -24,10 +24,10 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpr const a1 = f; // { (): number; g(): U; } const a2 = f.g; // () => number const a3 = f.g; // () => U - ~ + ~~~~~~~~ !!! error TS1477: Instantiation expression cannot be followed by property access. const a4 = f.g; // () => number - ~ + ~~~~~~~~ !!! error TS1477: Instantiation expression cannot be followed by property access. const a5 = f['g']; // () => number diff --git a/tests/baselines/reference/optionalChainWithInstantiationExpression1(target=es2019).errors.txt b/tests/baselines/reference/optionalChainWithInstantiationExpression1(target=es2019).errors.txt index e33356fc5a9bf..3bfcaf2d80c57 100644 --- a/tests/baselines/reference/optionalChainWithInstantiationExpression1(target=es2019).errors.txt +++ b/tests/baselines/reference/optionalChainWithInstantiationExpression1(target=es2019).errors.txt @@ -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) ==== @@ -14,7 +14,7 @@ tests/cases/compiler/optionalChainWithInstantiationExpression1.ts(12,9): error T declare const a: typeof A | undefined; a?.b.d; - ~ + ~~~ !!! error TS1477: Instantiation expression cannot be followed by property access. a?.b.d diff --git a/tests/baselines/reference/optionalChainWithInstantiationExpression1(target=es2020).errors.txt b/tests/baselines/reference/optionalChainWithInstantiationExpression1(target=es2020).errors.txt index e33356fc5a9bf..3bfcaf2d80c57 100644 --- a/tests/baselines/reference/optionalChainWithInstantiationExpression1(target=es2020).errors.txt +++ b/tests/baselines/reference/optionalChainWithInstantiationExpression1(target=es2020).errors.txt @@ -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) ==== @@ -14,7 +14,7 @@ tests/cases/compiler/optionalChainWithInstantiationExpression1.ts(12,9): error T declare const a: typeof A | undefined; a?.b.d; - ~ + ~~~ !!! error TS1477: Instantiation expression cannot be followed by property access. a?.b.d diff --git a/tests/baselines/reference/parserMemberAccessExpression1.errors.txt b/tests/baselines/reference/parserMemberAccessExpression1.errors.txt index 4f0d5b5eb0cd1..091565c31e21e 100644 --- a/tests/baselines/reference/parserMemberAccessExpression1.errors.txt +++ b/tests/baselines/reference/parserMemberAccessExpression1.errors.txt @@ -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'. @@ -23,12 +23,12 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression Foo.Bar(); ~~~ !!! error TS2304: Cannot find name 'Foo'. - ~~~ + ~~~ !!! error TS1477: Instantiation expression cannot be followed by property access. Foo.Bar(); ~~~ !!! error TS2304: Cannot find name 'Foo'. - ~~~ + ~~~ !!! error TS1477: Instantiation expression cannot be followed by property access. ~ !!! error TS2304: Cannot find name 'T'. diff --git a/tests/baselines/reference/parserMemberAccessOffOfGenericType1.errors.txt b/tests/baselines/reference/parserMemberAccessOffOfGenericType1.errors.txt index 9df16d7ea2aa8..e5ebfc726c45b 100644 --- a/tests/baselines/reference/parserMemberAccessOffOfGenericType1.errors.txt +++ b/tests/baselines/reference/parserMemberAccessOffOfGenericType1.errors.txt @@ -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.makeChild(); ~~~~ !!! error TS2304: Cannot find name 'List'. - ~~~~~~~~~ + ~~~~~~~~ !!! error TS1477: Instantiation expression cannot be followed by property access. \ No newline at end of file