File tree 4 files changed +19
-1
lines changed
4 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -1824,6 +1824,14 @@ export class FunctionDeclaration extends DeclarationStatement {
1824
1824
var typeParameters = this . typeParameters ;
1825
1825
return typeParameters != null && typeParameters . length > 0 ;
1826
1826
}
1827
+
1828
+ get firstStatement ( ) : Statement | null {
1829
+ var body = this . body ;
1830
+ if ( ! ( body && body . kind == NodeKind . BLOCK ) ) return null ;
1831
+ var statements = ( < BlockStatement > body ) . statements ;
1832
+ if ( statements . length < 0 ) return null ;
1833
+ return statements [ 0 ] ;
1834
+ }
1827
1835
}
1828
1836
1829
1837
/** Represents an `if` statement. */
Original file line number Diff line number Diff line change @@ -5244,7 +5244,14 @@ export class Compiler extends DiagnosticEmitter {
5244
5244
5245
5245
// call to `super()`
5246
5246
case ElementKind . CLASS : {
5247
- if ( expression . expression . kind == NodeKind . SUPER ) {
5247
+ if ( expression . expression . kind == NodeKind . SUPER && currentFunction . is ( CommonFlags . CONSTRUCTOR ) ) {
5248
+ if ( expression . parent != currentFunction . prototype . declaration . firstStatement ) {
5249
+ this . error (
5250
+ DiagnosticCode . A_super_call_must_be_the_first_statement_in_the_constructor ,
5251
+ expression . range
5252
+ ) ;
5253
+ return module . createUnreachable ( ) ;
5254
+ }
5248
5255
let classInstance = assert ( currentFunction . parent ) ;
5249
5256
assert ( classInstance . kind == ElementKind . CLASS ) ;
5250
5257
let expr = this . compileSuperInstantiate ( < Class > classInstance , expression . arguments , expression ) ;
Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ export enum DiagnosticCode {
101
101
The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_or_a_property_access = 2357 ,
102
102
The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access = 2364 ,
103
103
Operator_0_cannot_be_applied_to_types_1_and_2 = 2365 ,
104
+ A_super_call_must_be_the_first_statement_in_the_constructor = 2376 ,
104
105
Constructors_for_derived_classes_must_call_super_first = 2377 ,
105
106
_get_and_set_accessor_must_have_the_same_type = 2380 ,
106
107
Constructor_implementation_is_missing = 2390 ,
@@ -225,6 +226,7 @@ export function diagnosticCodeToString(code: DiagnosticCode): string {
225
226
case 2357 : return "The operand of an increment or decrement operator must be a variable or a property access." ;
226
227
case 2364 : return "The left-hand side of an assignment expression must be a variable or a property access." ;
227
228
case 2365 : return "Operator '{0}' cannot be applied to types '{1}' and '{2}'." ;
229
+ case 2376 : return "A 'super' call must be the first statement in the constructor." ;
228
230
case 2377 : return "Constructors for derived classes must call 'super' first." ;
229
231
case 2380 : return "'get' and 'set' accessor must have the same type." ;
230
232
case 2390 : return "Constructor implementation is missing." ;
Original file line number Diff line number Diff line change 95
95
"The operand of an increment or decrement operator must be a variable or a property access." : 2357 ,
96
96
"The left-hand side of an assignment expression must be a variable or a property access." : 2364 ,
97
97
"Operator '{0}' cannot be applied to types '{1}' and '{2}'." : 2365 ,
98
+ "A 'super' call must be the first statement in the constructor." : 2376 ,
98
99
"Constructors for derived classes must call 'super' first." : 2377 ,
99
100
"'get' and 'set' accessor must have the same type." : 2380 ,
100
101
"Constructor implementation is missing." : 2390 ,
You can’t perform that action at this time.
0 commit comments