@@ -6768,6 +6768,8 @@ export class Compiler extends DiagnosticEmitter {
67686768 ) ;
67696769 ctorInstance . set ( CommonFlags . INSTANCE | CommonFlags . CONSTRUCTOR | CommonFlags . COMPILED ) ;
67706770 classInstance . constructorInstance = ctorInstance ;
6771+ var previousFunction = this . currentFunction ;
6772+ this . currentFunction = ctorInstance ;
67716773
67726774 // generate body
67736775 var module = this . module ;
@@ -6799,6 +6801,7 @@ export class Compiler extends DiagnosticEmitter {
67996801 for ( let i = 0 ; i < numParameters ; ++ i ) {
68006802 operands [ i + 1 ] = module . createGetLocal ( i + 1 , parameterTypes [ i ] . toNativeType ( ) ) ;
68016803 }
6804+ // TODO: base constructor might be inlined, but makeCallDirect can't do this
68026805 stmts . push (
68036806 module . createSetLocal ( 0 ,
68046807 this . makeCallDirect ( assert ( baseClass . constructorInstance ) , operands )
@@ -6818,16 +6821,19 @@ export class Compiler extends DiagnosticEmitter {
68186821 : module . createBlock ( null , stmts , nativeSizeType )
68196822 ) ;
68206823 ctorInstance . finalize ( module , funcRef ) ;
6824+ this . currentFunction = previousFunction ;
68216825 return ctorInstance ;
68226826 }
68236827
68246828 compileInstantiate ( classInstance : Class , argumentExpressions : Expression [ ] , reportNode : Node ) : ExpressionRef {
6829+ var ctor = this . ensureConstructor ( classInstance , reportNode ) ;
68256830 var expr = this . compileCallDirect (
6826- this . ensureConstructor ( classInstance , reportNode ) ,
6831+ ctor ,
68276832 argumentExpressions ,
68286833 reportNode ,
6829- this . options . usizeType . toNativeZero ( this . module )
6830- // TODO: inlining
6834+ this . options . usizeType . toNativeZero ( this . module ) ,
6835+ ctor . hasDecorator ( DecoratorFlags . INLINE )
6836+ // FIXME: trying to inline a constructor that doesn't return a custom value doesn't work
68316837 ) ;
68326838 this . currentType = classInstance . type ;
68336839 return expr ;
@@ -7809,6 +7815,10 @@ export class Compiler extends DiagnosticEmitter {
78097815
78107816 /** Makes the initializers for a class's fields. */
78117817 makeFieldInitialization ( classInstance : Class , stmts : ExpressionRef [ ] = [ ] ) : ExpressionRef [ ] {
7818+
7819+ // must not be used in an inline context as it makes assumptions about local indexes
7820+ assert ( ! this . currentFunction . flow . is ( FlowFlags . INLINE_CONTEXT ) ) ;
7821+
78127822 if ( classInstance . members ) {
78137823 let module = this . module ;
78147824 let nativeSizeType = this . options . nativeSizeType ;
@@ -7833,6 +7843,8 @@ export class Compiler extends DiagnosticEmitter {
78337843 field . memoryOffset
78347844 ) ) ;
78357845 } else {
7846+ // NOTE: if all fields have initializers then this way is best, but if they don't,
7847+ // it would be more efficient to categorically zero memory on allocation.
78367848 let parameterIndex = ( < FieldDeclaration > field . prototype . declaration ) . parameterIndex ;
78377849 stmts . push ( module . createStore ( fieldType . byteSize ,
78387850 module . createGetLocal ( 0 , nativeSizeType ) ,
0 commit comments