@@ -5990,11 +5990,8 @@ export class Compiler extends DiagnosticEmitter {
59905990 if ( ! target ) return module . unreachable ( ) ;
59915991 let thisExpression = this . resolver . currentThisExpression ;
59925992
5993- let signature : Signature | null ;
5994- let functionArg : ExpressionRef ;
5993+ // handle direct call
59955994 switch ( target . kind ) {
5996-
5997- // direct call: concrete function
59985995 case ElementKind . FunctionPrototype : {
59995996 let functionPrototype = < FunctionPrototype > target ;
60005997 if ( functionPrototype . hasDecorator ( DecoratorFlags . Builtin ) ) {
@@ -6024,128 +6021,35 @@ export class Compiler extends DiagnosticEmitter {
60246021 constraints
60256022 ) ;
60266023 }
6024+ }
60276025
6028- // indirect call: first-class function (non-generic, can't be inlined)
6029- case ElementKind . Local : {
6030- let local = < Local > target ;
6031- signature = local . type . signatureReference ;
6032- if ( signature ) {
6033- if ( local . parent != flow . targetFunction ) {
6034- // TODO: closures
6035- this . error (
6036- DiagnosticCode . Not_implemented_0 ,
6037- expression . range ,
6038- "Closures"
6039- ) ;
6040- return module . unreachable ( ) ;
6041- }
6042- if ( local . is ( CommonFlags . Inlined ) ) {
6043- let inlinedValue = local . constantIntegerValue ;
6044- if ( this . options . isWasm64 ) {
6045- functionArg = module . i64 ( i64_low ( inlinedValue ) , i64_high ( inlinedValue ) ) ;
6046- } else {
6047- assert ( ! i64_high ( inlinedValue ) ) ;
6048- functionArg = module . i32 ( i64_low ( inlinedValue ) ) ;
6049- }
6050- } else {
6051- functionArg = module . local_get ( local . index , this . options . sizeTypeRef ) ;
6052- }
6053- break ;
6054- }
6055- this . error (
6056- DiagnosticCode . Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures ,
6057- expression . range , local . type . toString ( )
6058- ) ;
6059- return module . unreachable ( ) ;
6060- }
6061- case ElementKind . Global : {
6062- let global = < Global > target ;
6063- signature = global . type . signatureReference ;
6064- if ( signature ) {
6065- functionArg = module . global_get ( global . internalName , global . type . toRef ( ) ) ;
6066- break ;
6067- }
6068- this . error (
6069- DiagnosticCode . Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures ,
6070- expression . range , global . type . toString ( )
6026+ // handle indirect call
6027+ let functionArg = this . compileExpression ( expression . expression , Type . auto ) ;
6028+ let signature = this . currentType . getSignature ( ) ;
6029+ if ( signature ) {
6030+ return this . compileCallIndirect (
6031+ signature ,
6032+ functionArg ,
6033+ expression . args ,
6034+ expression ,
6035+ 0 ,
6036+ contextualType == Type . void
6037+ ) ;
6038+ }
6039+ this . error (
6040+ DiagnosticCode . Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures ,
6041+ expression . range , this . currentType . toString ( )
6042+ ) ;
6043+ if ( target . kind == ElementKind . PropertyPrototype ) {
6044+ let getterPrototype = ( < PropertyPrototype > target ) . getterPrototype ;
6045+ if ( getterPrototype ) {
6046+ this . infoRelated (
6047+ DiagnosticCode . This_expression_is_not_callable_because_it_is_a_get_accessor_Did_you_mean_to_use_it_without ,
6048+ expression . range , getterPrototype . identifierNode . range
60716049 ) ;
6072- return module . unreachable ( ) ;
6073- }
6074- case ElementKind . PropertyPrototype : {
6075- let propertyInstance = this . resolver . resolveProperty ( < PropertyPrototype > target ) ;
6076- if ( ! propertyInstance ) return module . unreachable ( ) ;
6077- target = propertyInstance ;
6078- // fall-through
6079- }
6080- case ElementKind . Property : {
6081- let propertyInstance = < Property > target ;
6082- let getterInstance = propertyInstance . getterInstance ;
6083- let type = assert ( this . resolver . getTypeOfElement ( target ) ) ;
6084-
6085- if ( ! getterInstance ) {
6086- this . error (
6087- DiagnosticCode . Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures ,
6088- expression . range , type . toString ( )
6089- ) ;
6090- return module . unreachable ( ) ;
6091- }
6092-
6093- let thisArg : ExpressionRef = 0 ;
6094- if ( propertyInstance . is ( CommonFlags . Instance ) ) {
6095- thisArg = this . compileExpression (
6096- assert ( thisExpression ) ,
6097- assert ( getterInstance . signature . thisType ) ,
6098- Constraints . ConvImplicit | Constraints . IsThis
6099- ) ;
6100- }
6101- functionArg = this . compileCallDirect ( getterInstance , [ ] , expression . expression , thisArg ) ;
6102- signature = this . currentType . signatureReference ;
6103- if ( ! signature ) {
6104- this . error (
6105- DiagnosticCode . Cannot_invoke_an_expression_whose_type_lacks_a_call_signature_Type_0_has_no_compatible_call_signatures ,
6106- expression . range , this . currentType . toString ( )
6107- ) ;
6108- return module . unreachable ( ) ;
6109- }
6110- break ;
6111- }
6112- case ElementKind . Class : {
6113- let classInstance = < Class > target ;
6114- let typeArguments = classInstance . getTypeArgumentsTo ( this . program . functionPrototype ) ;
6115- if ( typeArguments && typeArguments . length > 0 ) {
6116- let ftype = typeArguments [ 0 ] ;
6117- signature = ftype . getSignature ( ) ;
6118- functionArg = this . compileExpression ( expression . expression , ftype , Constraints . ConvImplicit ) ;
6119- break ;
6120- }
6121- // fall-through
6122- }
6123-
6124- // not supported
6125- default : {
6126- let type = this . resolver . getTypeOfElement ( target ) ;
6127- if ( type ) {
6128- this . error (
6129- DiagnosticCode . Type_0_has_no_call_signatures ,
6130- expression . range , type . toString ( )
6131- ) ;
6132- } else {
6133- this . error (
6134- DiagnosticCode . Expression_cannot_be_represented_by_a_type ,
6135- expression . range
6136- ) ;
6137- }
6138- return module . unreachable ( ) ;
61396050 }
61406051 }
6141- return this . compileCallIndirect (
6142- assert ( signature ) , // FIXME: bootstrap can't see this yet
6143- functionArg ,
6144- expression . args ,
6145- expression ,
6146- 0 ,
6147- contextualType == Type . void
6148- ) ;
6052+ return module . unreachable ( ) ;
61496053 }
61506054
61516055 /** Compiles the given arguments like a call expression according to the specified context. */
0 commit comments