Skip to content

Commit 9336886

Browse files
committed
Added more specific diagnostic message
1 parent f89156b commit 9336886

9 files changed

+28
-24
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10405,7 +10405,7 @@ namespace ts {
1040510405
return baseConstructorType === nullWideningType;
1040610406
}
1040710407

10408-
function checkThisBeforeSuper(node: Node, container: Node) {
10408+
function checkThisBeforeSuper(node: Node, container: Node, diagnosticMessage: DiagnosticMessage) {
1040910409
const containingClassDecl = <ClassDeclaration>container.parent;
1041010410
const baseTypeNode = getClassExtendsHeritageClauseElement(containingClassDecl);
1041110411

@@ -10423,7 +10423,7 @@ namespace ts {
1042310423
// "this" is not accessed as a parameter of the super-call.
1042410424
if (!superCall || superCall.end > node.pos) {
1042510425
// In ES6, super inside constructor of class-declaration has to precede "this" accessing
10426-
error(node, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class);
10426+
error(node, diagnosticMessage);
1042710427
}
1042810428
}
1042910429
}
@@ -10435,7 +10435,7 @@ namespace ts {
1043510435
let needToCaptureLexicalThis = false;
1043610436

1043710437
if (container.kind === SyntaxKind.Constructor) {
10438-
checkThisBeforeSuper(node, container);
10438+
checkThisBeforeSuper(node, container, Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class);
1043910439
}
1044010440

1044110441
// Now skip arrow functions to get the "real" owner of 'this'.
@@ -10584,7 +10584,7 @@ namespace ts {
1058410584
}
1058510585

1058610586
if (!isCallExpression && container.kind === SyntaxKind.Constructor) {
10587-
checkThisBeforeSuper(node, container);
10587+
checkThisBeforeSuper(node, container, Diagnostics.super_must_be_called_before_accessing_a_property_of_super_in_the_constructor_of_a_derived_class);
1058810588
}
1058910589

1059010590
if ((getModifierFlags(container) & ModifierFlags.Static) || isCallExpression) {

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3165,6 +3165,10 @@
31653165
"category": "Error",
31663166
"code": 17010
31673167
},
3168+
"'super' must be called before accessing a property of 'super' in the constructor of a derived class.": {
3169+
"category": "Error",
3170+
"code": 17011
3171+
},
31683172

31693173
"Circularity detected while resolving configuration: {0}": {
31703174
"category": "Error",

tests/baselines/reference/superAccess2.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ tests/cases/compiler/superAccess2.ts(7,15): error TS1034: 'super' must be follow
22
tests/cases/compiler/superAccess2.ts(8,17): error TS2338: 'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.
33
tests/cases/compiler/superAccess2.ts(8,22): error TS1034: 'super' must be followed by an argument list or member access.
44
tests/cases/compiler/superAccess2.ts(11,28): error TS2336: 'super' cannot be referenced in constructor arguments.
5-
tests/cases/compiler/superAccess2.ts(11,28): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
5+
tests/cases/compiler/superAccess2.ts(11,28): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
66
tests/cases/compiler/superAccess2.ts(11,33): error TS1034: 'super' must be followed by an argument list or member access.
77
tests/cases/compiler/superAccess2.ts(11,40): error TS2336: 'super' cannot be referenced in constructor arguments.
8-
tests/cases/compiler/superAccess2.ts(11,40): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
8+
tests/cases/compiler/superAccess2.ts(11,40): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
99
tests/cases/compiler/superAccess2.ts(11,45): error TS1034: 'super' must be followed by an argument list or member access.
1010
tests/cases/compiler/superAccess2.ts(11,59): error TS2336: 'super' cannot be referenced in constructor arguments.
11-
tests/cases/compiler/superAccess2.ts(11,59): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
11+
tests/cases/compiler/superAccess2.ts(11,59): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
1212
tests/cases/compiler/superAccess2.ts(11,64): error TS1034: 'super' must be followed by an argument list or member access.
1313
tests/cases/compiler/superAccess2.ts(15,19): error TS1034: 'super' must be followed by an argument list or member access.
1414
tests/cases/compiler/superAccess2.ts(17,15): error TS2339: Property 'y' does not exist on type 'P'.
@@ -37,19 +37,19 @@ tests/cases/compiler/superAccess2.ts(21,15): error TS2339: Property 'x' does not
3737
~~~~~
3838
!!! error TS2336: 'super' cannot be referenced in constructor arguments.
3939
~~~~~
40-
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
40+
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
4141
~
4242
!!! error TS1034: 'super' must be followed by an argument list or member access.
4343
~~~~~
4444
!!! error TS2336: 'super' cannot be referenced in constructor arguments.
4545
~~~~~
46-
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
46+
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
4747
~
4848
!!! error TS1034: 'super' must be followed by an argument list or member access.
4949
~~~~~
5050
!!! error TS2336: 'super' cannot be referenced in constructor arguments.
5151
~~~~~
52-
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
52+
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
5353
~
5454
!!! error TS1034: 'super' must be followed by an argument list or member access.
5555
super();

tests/baselines/reference/superInConstructorParam1.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/compiler/superInConstructorParam1.ts(8,3): error TS2377: Constructors for derived classes must contain a 'super' call.
22
tests/cases/compiler/superInConstructorParam1.ts(8,19): error TS2336: 'super' cannot be referenced in constructor arguments.
3-
tests/cases/compiler/superInConstructorParam1.ts(8,19): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
3+
tests/cases/compiler/superInConstructorParam1.ts(8,19): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
44

55

66
==== tests/cases/compiler/superInConstructorParam1.ts (3 errors) ====
@@ -16,7 +16,7 @@ tests/cases/compiler/superInConstructorParam1.ts(8,19): error TS17009: 'super' m
1616
~~~~~
1717
!!! error TS2336: 'super' cannot be referenced in constructor arguments.
1818
~~~~~
19-
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
19+
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
2020
}
2121
~~~
2222
!!! error TS2377: Constructors for derived classes must contain a 'super' call.

tests/baselines/reference/superNewCall1.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/compiler/superNewCall1.ts(9,5): error TS2377: Constructors for derived classes must contain a 'super' call.
22
tests/cases/compiler/superNewCall1.ts(10,9): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
3-
tests/cases/compiler/superNewCall1.ts(10,13): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
3+
tests/cases/compiler/superNewCall1.ts(10,13): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
44

55

66
==== tests/cases/compiler/superNewCall1.ts (3 errors) ====
@@ -19,7 +19,7 @@ tests/cases/compiler/superNewCall1.ts(10,13): error TS17009: 'super' must be cal
1919
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020
!!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
2121
~~~~~
22-
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
22+
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
2323
}
2424
~~~~~
2525
!!! error TS2377: Constructors for derived classes must contain a 'super' call.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
tests/cases/conformance/classes/constructorDeclarations/superCalls/superPropertyInConstructorBeforeSuperCall.ts(7,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
2-
tests/cases/conformance/classes/constructorDeclarations/superCalls/superPropertyInConstructorBeforeSuperCall.ts(13,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
1+
tests/cases/conformance/classes/constructorDeclarations/superCalls/superPropertyInConstructorBeforeSuperCall.ts(7,9): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
2+
tests/cases/conformance/classes/constructorDeclarations/superCalls/superPropertyInConstructorBeforeSuperCall.ts(13,15): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
33

44

55
==== tests/cases/conformance/classes/constructorDeclarations/superCalls/superPropertyInConstructorBeforeSuperCall.ts (2 errors) ====
@@ -11,14 +11,14 @@ tests/cases/conformance/classes/constructorDeclarations/superCalls/superProperty
1111
constructor() {
1212
super.x();
1313
~~~~~
14-
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
14+
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
1515
super();
1616
}
1717
}
1818
class C2 extends B {
1919
constructor() {
2020
super(super.x());
2121
~~~~~
22-
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
22+
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
2323
}
2424
}

tests/baselines/reference/superWithTypeArgument.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/compiler/superWithTypeArgument.ts(6,5): error TS2377: Constructors for derived classes must contain a 'super' call.
2-
tests/cases/compiler/superWithTypeArgument.ts(7,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
2+
tests/cases/compiler/superWithTypeArgument.ts(7,9): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
33
tests/cases/compiler/superWithTypeArgument.ts(7,14): error TS1034: 'super' must be followed by an argument list or member access.
44

55

@@ -14,7 +14,7 @@ tests/cases/compiler/superWithTypeArgument.ts(7,14): error TS1034: 'super' must
1414
super<T>();
1515
~~~~~~~~~~~~~~~~~~~
1616
~~~~~
17-
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
17+
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
1818
~
1919
!!! error TS1034: 'super' must be followed by an argument list or member access.
2020
}

tests/baselines/reference/superWithTypeArgument2.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/compiler/superWithTypeArgument2.ts(6,5): error TS2377: Constructors for derived classes must contain a 'super' call.
2-
tests/cases/compiler/superWithTypeArgument2.ts(7,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
2+
tests/cases/compiler/superWithTypeArgument2.ts(7,9): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
33
tests/cases/compiler/superWithTypeArgument2.ts(7,14): error TS1034: 'super' must be followed by an argument list or member access.
44

55

@@ -14,7 +14,7 @@ tests/cases/compiler/superWithTypeArgument2.ts(7,14): error TS1034: 'super' must
1414
super<T>(x);
1515
~~~~~~~~~~~~~~~~~~~~
1616
~~~~~
17-
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
17+
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
1818
~
1919
!!! error TS1034: 'super' must be followed by an argument list or member access.
2020
}

tests/baselines/reference/superWithTypeArgument3.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/compiler/superWithTypeArgument3.ts(7,5): error TS2377: Constructors for derived classes must contain a 'super' call.
2-
tests/cases/compiler/superWithTypeArgument3.ts(8,9): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
2+
tests/cases/compiler/superWithTypeArgument3.ts(8,9): error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
33
tests/cases/compiler/superWithTypeArgument3.ts(8,14): error TS1034: 'super' must be followed by an argument list or member access.
44

55

@@ -15,7 +15,7 @@ tests/cases/compiler/superWithTypeArgument3.ts(8,14): error TS1034: 'super' must
1515
super<T>();
1616
~~~~~~~~~~~~~~~~~~~
1717
~~~~~
18-
!!! error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class.
18+
!!! error TS17011: 'super' must be called before accessing a property of 'super' in the constructor of a derived class.
1919
~
2020
!!! error TS1034: 'super' must be followed by an argument list or member access.
2121
}

0 commit comments

Comments
 (0)