Skip to content

Commit 61e954b

Browse files
author
Kanchalai Tanglertsampan
committed
Address PR: report error on super call instead of entire constructor node
1 parent dc8e0cc commit 61e954b

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11886,10 +11886,10 @@ namespace ts {
1188611886
const containingClassDecl = <ClassDeclaration>node.parent;
1188711887
if (getClassExtendsHeritageClauseElement(containingClassDecl)) {
1188811888
const classExtendsNull = classDeclarationExtendsNull(containingClassDecl);
11889-
11890-
if (getSuperCallInConstructor(node)) {
11889+
const superCall = getSuperCallInConstructor(node);
11890+
if (superCall) {
1189111891
if (classExtendsNull) {
11892-
error(node, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
11892+
error(superCall, Diagnostics.A_constructor_cannot_contain_a_super_call_when_its_class_extends_null);
1189311893
}
1189411894

1189511895
// The first statement in the body of a constructor (excluding prologue directives) must be a super call

tests/baselines/reference/classExtendsNull.errors.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
tests/cases/compiler/classExtendsNull.ts(2,5): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
1+
tests/cases/compiler/classExtendsNull.ts(3,9): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
22

33

44
==== tests/cases/compiler/classExtendsNull.ts (1 errors) ====
55
class C extends null {
66
constructor() {
7-
~~~~~~~~~~~~~~~
87
super();
9-
~~~~~~~~~~~~~~~~
8+
~~~~~~~
9+
!!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
1010
return Object.create(null);
11-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1211
}
13-
~~~~~
14-
!!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
1512
}
1613

1714
class D extends null {
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
1-
tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts(3,5): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
2-
tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts(11,5): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
1+
tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts(5,9): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
2+
tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts(12,9): error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
33

44

55
==== tests/cases/conformance/es6/classDeclaration/superCallBeforeThisAccessing4.ts (2 errors) ====
66
class D extends null {
77
private _t;
88
constructor() {
9-
~~~~~~~~~~~~~~~
109
this._t;
11-
~~~~~~~~~~~~~~~~
1210
super();
13-
~~~~~~~~~~~~~~~~
14-
}
15-
~~~~~
11+
~~~~~~~
1612
!!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
13+
}
1714
}
1815

1916
class E extends null {
2017
private _t;
2118
constructor() {
22-
~~~~~~~~~~~~~~~
2319
super();
24-
~~~~~~~~~~~~~~~~
20+
~~~~~~~
21+
!!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
2522
this._t;
26-
~~~~~~~~~~~~~~~~
2723
}
28-
~~~~~
29-
!!! error TS17005: A constructor cannot contain a 'super' call when its class extends 'null'
3024
}

0 commit comments

Comments
 (0)