@@ -7110,6 +7110,13 @@ export class Compiler extends DiagnosticEmitter {
7110
7110
// Compile the called function's body in the scope of the inlined flow
7111
7111
this . compileFunctionBody ( instance , body ) ;
7112
7112
7113
+ // If a constructor, perform field init checks on its flow directly
7114
+ if ( instance . is ( CommonFlags . CONSTRUCTOR ) ) {
7115
+ let parent = instance . parent ;
7116
+ assert ( parent . kind == ElementKind . CLASS ) ;
7117
+ this . checkFieldInitializationInFlow ( < Class > parent , flow ) ;
7118
+ }
7119
+
7113
7120
// Free any new scoped locals and reset to the original flow
7114
7121
if ( ! flow . is ( FlowFlags . TERMINATES ) ) {
7115
7122
this . performAutoreleases ( flow , body ) ;
@@ -9326,7 +9333,11 @@ export class Compiler extends DiagnosticEmitter {
9326
9333
if ( ! classInstance ) return module . unreachable ( ) ;
9327
9334
if ( contextualType == Type . void ) constraints |= Constraints . WILL_DROP ;
9328
9335
var ctor = this . ensureConstructor ( classInstance , expression ) ;
9329
- this . checkFieldInitialization ( classInstance , expression ) ;
9336
+ if ( ! ctor . hasDecorator ( DecoratorFlags . INLINE ) ) {
9337
+ // Inlined ctors haven't been compiled yet and are checked upon inline
9338
+ // compilation of their body instead.
9339
+ this . checkFieldInitialization ( classInstance , expression ) ;
9340
+ }
9330
9341
return this . compileInstantiate ( ctor , expression . args , constraints , expression ) ;
9331
9342
}
9332
9343
@@ -9453,10 +9464,14 @@ export class Compiler extends DiagnosticEmitter {
9453
9464
checkFieldInitialization ( classInstance : Class , relatedNode : Node | null = null ) : void {
9454
9465
if ( classInstance . didCheckFieldInitialization ) return ;
9455
9466
classInstance . didCheckFieldInitialization = true ;
9467
+ var ctor = assert ( classInstance . constructorInstance ) ;
9468
+ this . checkFieldInitializationInFlow ( classInstance , ctor . flow , relatedNode ) ;
9469
+ }
9470
+
9471
+ /** Checks that all class fields have been initialized in the specified flow. */
9472
+ checkFieldInitializationInFlow ( classInstance : Class , flow : Flow , relatedNode : Node | null = null ) : void {
9456
9473
var members = classInstance . members ;
9457
9474
if ( members ) {
9458
- let ctor = assert ( classInstance . constructorInstance ) ;
9459
- let flow = ctor . flow ;
9460
9475
for ( let _values = Map_values ( members ) , i = 0 , k = _values . length ; i < k ; ++ i ) {
9461
9476
let element = _values [ i ] ;
9462
9477
if ( element . kind == ElementKind . FIELD && element . parent == classInstance ) {
0 commit comments