From 0e4c07bb2e517fbdb9b8ac8824ddbf68cb5e37a4 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Thu, 30 Jun 2022 18:39:56 +0300 Subject: [PATCH 1/2] fix(49704): parse type arguments in super call expression --- src/compiler/parser.ts | 5 ++++- tests/baselines/reference/errorSuperCalls.errors.txt | 5 ++++- .../reference/parserSuperExpression2.symbols | 1 + .../reference/superWithTypeArgument.errors.txt | 5 ++++- .../baselines/reference/superWithTypeArgument.symbols | 1 + .../reference/superWithTypeArgument2.errors.txt | 6 +++--- .../reference/superWithTypeArgument2.symbols | 1 + .../reference/superWithTypeArgument3.errors.txt | 5 ++++- .../reference/superWithTypeArgument3.symbols | 1 + tests/cases/fourslash/getOutliningSpans.ts | 11 ++++++++++- 10 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 44eac8738967f..a90557a523f7e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -5285,12 +5285,15 @@ namespace ts { function parseSuperExpression(): MemberExpression { const pos = getNodePos(); - const expression = parseTokenNode(); + let expression = parseTokenNode(); if (token() === SyntaxKind.LessThanToken) { const startPos = getNodePos(); const typeArguments = tryParse(parseTypeArgumentsInExpression); if (typeArguments !== undefined) { parseErrorAt(startPos, getNodePos(), Diagnostics.super_may_not_use_type_arguments); + if (!isTemplateStartOfTaggedTemplate()) { + expression = factory.createExpressionWithTypeArguments(expression, typeArguments); + } } } diff --git a/tests/baselines/reference/errorSuperCalls.errors.txt b/tests/baselines/reference/errorSuperCalls.errors.txt index 5d53d6719e08b..99b02f4022599 100644 --- a/tests/baselines/reference/errorSuperCalls.errors.txt +++ b/tests/baselines/reference/errorSuperCalls.errors.txt @@ -8,13 +8,14 @@ tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(30,16): error tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(34,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(38,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(46,14): error TS2754: 'super' may not use type arguments. +tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(46,15): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(58,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(62,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(67,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(71,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. -==== tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts (14 errors) ==== +==== tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts (15 errors) ==== //super call in class constructor with no base type class NoBase { constructor() { @@ -81,6 +82,8 @@ tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(71,9): error T super(); ~~~~~~~~ !!! error TS2754: 'super' may not use type arguments. + ~~~~~~ +!!! error TS2558: Expected 0 type arguments, but got 1. super(); } } diff --git a/tests/baselines/reference/parserSuperExpression2.symbols b/tests/baselines/reference/parserSuperExpression2.symbols index c382e54855f05..47fff63acce15 100644 --- a/tests/baselines/reference/parserSuperExpression2.symbols +++ b/tests/baselines/reference/parserSuperExpression2.symbols @@ -6,5 +6,6 @@ class C { >M : Symbol(C.M, Decl(parserSuperExpression2.ts, 0, 9)) super(0); +>T : Symbol(T) } } diff --git a/tests/baselines/reference/superWithTypeArgument.errors.txt b/tests/baselines/reference/superWithTypeArgument.errors.txt index 3ea27e403f468..62b2113d178e4 100644 --- a/tests/baselines/reference/superWithTypeArgument.errors.txt +++ b/tests/baselines/reference/superWithTypeArgument.errors.txt @@ -1,7 +1,8 @@ tests/cases/compiler/superWithTypeArgument.ts(7,14): error TS2754: 'super' may not use type arguments. +tests/cases/compiler/superWithTypeArgument.ts(7,15): error TS2558: Expected 0 type arguments, but got 1. -==== tests/cases/compiler/superWithTypeArgument.ts (1 errors) ==== +==== tests/cases/compiler/superWithTypeArgument.ts (2 errors) ==== class C { } @@ -11,5 +12,7 @@ tests/cases/compiler/superWithTypeArgument.ts(7,14): error TS2754: 'super' may n super(); ~~~ !!! error TS2754: 'super' may not use type arguments. + ~ +!!! error TS2558: Expected 0 type arguments, but got 1. } } \ No newline at end of file diff --git a/tests/baselines/reference/superWithTypeArgument.symbols b/tests/baselines/reference/superWithTypeArgument.symbols index 50990b4817e68..eeb5919958f84 100644 --- a/tests/baselines/reference/superWithTypeArgument.symbols +++ b/tests/baselines/reference/superWithTypeArgument.symbols @@ -12,5 +12,6 @@ class D extends C { constructor() { super(); >super : Symbol(C, Decl(superWithTypeArgument.ts, 0, 0)) +>T : Symbol(T, Decl(superWithTypeArgument.ts, 4, 8)) } } diff --git a/tests/baselines/reference/superWithTypeArgument2.errors.txt b/tests/baselines/reference/superWithTypeArgument2.errors.txt index 01cb6d31e3223..a9fba3733f311 100644 --- a/tests/baselines/reference/superWithTypeArgument2.errors.txt +++ b/tests/baselines/reference/superWithTypeArgument2.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/superWithTypeArgument2.ts(7,14): error TS2754: 'super' may not use type arguments. -tests/cases/compiler/superWithTypeArgument2.ts(7,18): error TS2554: Expected 0 arguments, but got 1. +tests/cases/compiler/superWithTypeArgument2.ts(7,15): error TS2558: Expected 0 type arguments, but got 1. ==== tests/cases/compiler/superWithTypeArgument2.ts (2 errors) ==== @@ -12,7 +12,7 @@ tests/cases/compiler/superWithTypeArgument2.ts(7,18): error TS2554: Expected 0 a super(x); ~~~ !!! error TS2754: 'super' may not use type arguments. - ~ -!!! error TS2554: Expected 0 arguments, but got 1. + ~ +!!! error TS2558: Expected 0 type arguments, but got 1. } } \ No newline at end of file diff --git a/tests/baselines/reference/superWithTypeArgument2.symbols b/tests/baselines/reference/superWithTypeArgument2.symbols index 35a371cde104b..c42450e872384 100644 --- a/tests/baselines/reference/superWithTypeArgument2.symbols +++ b/tests/baselines/reference/superWithTypeArgument2.symbols @@ -19,6 +19,7 @@ class D extends C { super(x); >super : Symbol(C, Decl(superWithTypeArgument2.ts, 0, 0)) +>T : Symbol(T, Decl(superWithTypeArgument2.ts, 4, 8)) >x : Symbol(x, Decl(superWithTypeArgument2.ts, 5, 16)) } } diff --git a/tests/baselines/reference/superWithTypeArgument3.errors.txt b/tests/baselines/reference/superWithTypeArgument3.errors.txt index fc6d10fd80c7c..2ee28dd339ae5 100644 --- a/tests/baselines/reference/superWithTypeArgument3.errors.txt +++ b/tests/baselines/reference/superWithTypeArgument3.errors.txt @@ -1,7 +1,8 @@ tests/cases/compiler/superWithTypeArgument3.ts(8,14): error TS2754: 'super' may not use type arguments. +tests/cases/compiler/superWithTypeArgument3.ts(8,15): error TS2558: Expected 0 type arguments, but got 1. -==== tests/cases/compiler/superWithTypeArgument3.ts (1 errors) ==== +==== tests/cases/compiler/superWithTypeArgument3.ts (2 errors) ==== class C { foo: T; bar(x: U) { } @@ -12,6 +13,8 @@ tests/cases/compiler/superWithTypeArgument3.ts(8,14): error TS2754: 'super' may super(); ~~~ !!! error TS2754: 'super' may not use type arguments. + ~ +!!! error TS2558: Expected 0 type arguments, but got 1. } bar() { super.bar(null); diff --git a/tests/baselines/reference/superWithTypeArgument3.symbols b/tests/baselines/reference/superWithTypeArgument3.symbols index a596264aa7d85..9a6ff93596195 100644 --- a/tests/baselines/reference/superWithTypeArgument3.symbols +++ b/tests/baselines/reference/superWithTypeArgument3.symbols @@ -23,6 +23,7 @@ class D extends C { constructor() { super(); >super : Symbol(C, Decl(superWithTypeArgument3.ts, 0, 0)) +>T : Symbol(T, Decl(superWithTypeArgument3.ts, 5, 8)) } bar() { >bar : Symbol(D.bar, Decl(superWithTypeArgument3.ts, 8, 5)) diff --git a/tests/cases/fourslash/getOutliningSpans.ts b/tests/cases/fourslash/getOutliningSpans.ts index a522d47ce8bb8..5d70c5c6dc797 100644 --- a/tests/cases/fourslash/getOutliningSpans.ts +++ b/tests/cases/fourslash/getOutliningSpans.ts @@ -114,6 +114,15 @@ //// 2 //// ]|] ////)|]; - +//// +////class C[| { +//// foo: T; +////}|] +//// +////class D extends C[| { +//// constructor(x)[| { +//// super(x); +//// }|] +////}|] verify.outliningSpansInCurrentFile(test.ranges(), "code"); From d51e2f413ec4859cea86586f7d34e64c87bc7271 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 19 Jul 2022 15:38:08 +0300 Subject: [PATCH 2/2] omit duplicate errors --- src/compiler/checker.ts | 2 +- tests/baselines/reference/errorSuperCalls.errors.txt | 5 +---- tests/baselines/reference/superWithTypeArgument.errors.txt | 5 +---- tests/baselines/reference/superWithTypeArgument2.errors.txt | 6 +++--- tests/baselines/reference/superWithTypeArgument3.errors.txt | 5 +---- 5 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 13c50d3b770b3..3016fa8925d1d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -30648,7 +30648,7 @@ namespace ts { let typeArguments: NodeArray | undefined; - if (!isDecorator) { + if (!isDecorator && !isSuperCall(node)) { typeArguments = (node as CallExpression).typeArguments; // We already perform checking on the type arguments on the class declaration itself. diff --git a/tests/baselines/reference/errorSuperCalls.errors.txt b/tests/baselines/reference/errorSuperCalls.errors.txt index 99b02f4022599..5d53d6719e08b 100644 --- a/tests/baselines/reference/errorSuperCalls.errors.txt +++ b/tests/baselines/reference/errorSuperCalls.errors.txt @@ -8,14 +8,13 @@ tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(30,16): error tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(34,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(38,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(46,14): error TS2754: 'super' may not use type arguments. -tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(46,15): error TS2558: Expected 0 type arguments, but got 1. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(58,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(62,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(67,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(71,9): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors. -==== tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts (15 errors) ==== +==== tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts (14 errors) ==== //super call in class constructor with no base type class NoBase { constructor() { @@ -82,8 +81,6 @@ tests/cases/conformance/expressions/superCalls/errorSuperCalls.ts(71,9): error T super(); ~~~~~~~~ !!! error TS2754: 'super' may not use type arguments. - ~~~~~~ -!!! error TS2558: Expected 0 type arguments, but got 1. super(); } } diff --git a/tests/baselines/reference/superWithTypeArgument.errors.txt b/tests/baselines/reference/superWithTypeArgument.errors.txt index 62b2113d178e4..3ea27e403f468 100644 --- a/tests/baselines/reference/superWithTypeArgument.errors.txt +++ b/tests/baselines/reference/superWithTypeArgument.errors.txt @@ -1,8 +1,7 @@ tests/cases/compiler/superWithTypeArgument.ts(7,14): error TS2754: 'super' may not use type arguments. -tests/cases/compiler/superWithTypeArgument.ts(7,15): error TS2558: Expected 0 type arguments, but got 1. -==== tests/cases/compiler/superWithTypeArgument.ts (2 errors) ==== +==== tests/cases/compiler/superWithTypeArgument.ts (1 errors) ==== class C { } @@ -12,7 +11,5 @@ tests/cases/compiler/superWithTypeArgument.ts(7,15): error TS2558: Expected 0 ty super(); ~~~ !!! error TS2754: 'super' may not use type arguments. - ~ -!!! error TS2558: Expected 0 type arguments, but got 1. } } \ No newline at end of file diff --git a/tests/baselines/reference/superWithTypeArgument2.errors.txt b/tests/baselines/reference/superWithTypeArgument2.errors.txt index a9fba3733f311..01cb6d31e3223 100644 --- a/tests/baselines/reference/superWithTypeArgument2.errors.txt +++ b/tests/baselines/reference/superWithTypeArgument2.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/superWithTypeArgument2.ts(7,14): error TS2754: 'super' may not use type arguments. -tests/cases/compiler/superWithTypeArgument2.ts(7,15): error TS2558: Expected 0 type arguments, but got 1. +tests/cases/compiler/superWithTypeArgument2.ts(7,18): error TS2554: Expected 0 arguments, but got 1. ==== tests/cases/compiler/superWithTypeArgument2.ts (2 errors) ==== @@ -12,7 +12,7 @@ tests/cases/compiler/superWithTypeArgument2.ts(7,15): error TS2558: Expected 0 t super(x); ~~~ !!! error TS2754: 'super' may not use type arguments. - ~ -!!! error TS2558: Expected 0 type arguments, but got 1. + ~ +!!! error TS2554: Expected 0 arguments, but got 1. } } \ No newline at end of file diff --git a/tests/baselines/reference/superWithTypeArgument3.errors.txt b/tests/baselines/reference/superWithTypeArgument3.errors.txt index 2ee28dd339ae5..fc6d10fd80c7c 100644 --- a/tests/baselines/reference/superWithTypeArgument3.errors.txt +++ b/tests/baselines/reference/superWithTypeArgument3.errors.txt @@ -1,8 +1,7 @@ tests/cases/compiler/superWithTypeArgument3.ts(8,14): error TS2754: 'super' may not use type arguments. -tests/cases/compiler/superWithTypeArgument3.ts(8,15): error TS2558: Expected 0 type arguments, but got 1. -==== tests/cases/compiler/superWithTypeArgument3.ts (2 errors) ==== +==== tests/cases/compiler/superWithTypeArgument3.ts (1 errors) ==== class C { foo: T; bar(x: U) { } @@ -13,8 +12,6 @@ tests/cases/compiler/superWithTypeArgument3.ts(8,15): error TS2558: Expected 0 t super(); ~~~ !!! error TS2754: 'super' may not use type arguments. - ~ -!!! error TS2558: Expected 0 type arguments, but got 1. } bar() { super.bar(null);