@@ -66,7 +66,8 @@ module ts {
66
66
getAugmentedPropertiesOfApparentType : getAugmentedPropertiesOfApparentType ,
67
67
getRootSymbol : getRootSymbol ,
68
68
getContextualType : getContextualType ,
69
- getFullyQualifiedName : getFullyQualifiedName
69
+ getFullyQualifiedName : getFullyQualifiedName ,
70
+ getResolvedSignature : getResolvedSignature
70
71
} ;
71
72
72
73
var undefinedSymbol = createSymbol ( SymbolFlags . Property | SymbolFlags . Transient , "undefined" ) ;
@@ -4128,7 +4129,7 @@ module ts {
4128
4129
return unknownSignature ;
4129
4130
}
4130
4131
4131
- function isCandidateSignature ( node : CallExpression , signature : Signature ) {
4132
+ function signatureHasCorrectArity ( node : CallExpression , signature : Signature ) {
4132
4133
var args = node . arguments || emptyArray ;
4133
4134
return args . length >= signature . minArgumentCount &&
4134
4135
( signature . hasRestParameter || args . length <= signature . parameters . length ) &&
@@ -4142,15 +4143,15 @@ module ts {
4142
4143
// interface B extends A { (x: 'foo'): string }
4143
4144
// var b: B;
4144
4145
// b('foo') // <- here overloads should be processed as [(x:'foo'): string, (x: string): void]
4145
- function collectCandidates ( node : CallExpression , signatures : Signature [ ] ) : Signature [ ] {
4146
- var result : Signature [ ] = [ ] ;
4146
+ function collectCandidates ( node : CallExpression , signatures : Signature [ ] , candidatesOutArray : Signature [ ] ) : Signature [ ] {
4147
+ var result : Signature [ ] = candidatesOutArray || [ ] ;
4147
4148
var lastParent : Node ;
4148
4149
var lastSymbol : Symbol ;
4149
4150
var cutoffPos : number = 0 ;
4150
4151
var pos : number ;
4151
4152
for ( var i = 0 ; i < signatures . length ; i ++ ) {
4152
4153
var signature = signatures [ i ] ;
4153
- if ( isCandidateSignature ( node , signature ) ) {
4154
+ if ( true ) {
4154
4155
var symbol = signature . declaration && getSymbolOfNode ( signature . declaration ) ;
4155
4156
var parent = signature . declaration && signature . declaration . parent ;
4156
4157
if ( ! lastSymbol || symbol === lastSymbol ) {
@@ -4260,9 +4261,9 @@ module ts {
4260
4261
return true ;
4261
4262
}
4262
4263
4263
- function resolveCall ( node : CallExpression , signatures : Signature [ ] ) : Signature {
4264
+ function resolveCall ( node : CallExpression , signatures : Signature [ ] , candidatesOutArray : Signature [ ] ) : Signature {
4264
4265
forEach ( node . typeArguments , checkSourceElement ) ;
4265
- var candidates = collectCandidates ( node , signatures ) ;
4266
+ var candidates = collectCandidates ( node , signatures , candidatesOutArray ) ;
4266
4267
if ( ! candidates . length ) {
4267
4268
error ( node , Diagnostics . Supplied_parameters_do_not_match_any_signature_of_call_target ) ;
4268
4269
return resolveErrorCall ( node ) ;
@@ -4278,20 +4279,24 @@ module ts {
4278
4279
var relation = candidates . length === 1 ? assignableRelation : subtypeRelation ;
4279
4280
while ( true ) {
4280
4281
for ( var i = 0 ; i < candidates . length ; i ++ ) {
4282
+ if ( ! signatureHasCorrectArity ( node , candidates [ i ] ) ) {
4283
+ continue ;
4284
+ }
4285
+
4281
4286
while ( true ) {
4282
- var candidate = candidates [ i ] ;
4283
- if ( candidate . typeParameters ) {
4287
+ var candidateWithCorrectArity = candidates [ i ] ;
4288
+ if ( candidateWithCorrectArity . typeParameters ) {
4284
4289
var typeArguments = node . typeArguments ?
4285
- checkTypeArguments ( candidate , node . typeArguments ) :
4286
- inferTypeArguments ( candidate , args , excludeArgument ) ;
4287
- candidate = getSignatureInstantiation ( candidate , typeArguments ) ;
4290
+ checkTypeArguments ( candidateWithCorrectArity , node . typeArguments ) :
4291
+ inferTypeArguments ( candidateWithCorrectArity , args , excludeArgument ) ;
4292
+ candidateWithCorrectArity = getSignatureInstantiation ( candidateWithCorrectArity , typeArguments ) ;
4288
4293
}
4289
- if ( ! checkApplicableSignature ( node , candidate , relation , excludeArgument , /*reportErrors*/ false ) ) {
4294
+ if ( ! checkApplicableSignature ( node , candidateWithCorrectArity , relation , excludeArgument , /*reportErrors*/ false ) ) {
4290
4295
break ;
4291
4296
}
4292
4297
var index = excludeArgument ? indexOf ( excludeArgument , true ) : - 1 ;
4293
4298
if ( index < 0 ) {
4294
- return candidate ;
4299
+ return candidateWithCorrectArity ;
4295
4300
}
4296
4301
excludeArgument [ index ] = false ;
4297
4302
}
@@ -4301,17 +4306,26 @@ module ts {
4301
4306
}
4302
4307
relation = assignableRelation ;
4303
4308
}
4309
+
4304
4310
// No signatures were applicable. Now report errors based on the last applicable signature with
4305
4311
// no arguments excluded from assignability checks.
4306
- checkApplicableSignature ( node , candidate , relation , undefined , /*reportErrors*/ true ) ;
4312
+ // If candidate is undefined, it means that no candidates had a suitable arity. In that case,
4313
+ // skip the checkApplicableSignature check.
4314
+ if ( candidateWithCorrectArity ) {
4315
+ checkApplicableSignature ( node , candidateWithCorrectArity , relation , undefined , /*reportErrors*/ true ) ;
4316
+ }
4317
+ else {
4318
+ error ( node , Diagnostics . Supplied_parameters_do_not_match_any_signature_of_call_target ) ;
4319
+ return resolveErrorCall ( node ) ;
4320
+ }
4307
4321
return resolveErrorCall ( node ) ;
4308
4322
}
4309
4323
4310
- function resolveCallExpression ( node : CallExpression ) : Signature {
4324
+ function resolveCallExpression ( node : CallExpression , candidatesOutArray : Signature [ ] ) : Signature {
4311
4325
if ( node . func . kind === SyntaxKind . SuperKeyword ) {
4312
4326
var superType = checkSuperExpression ( node . func ) ;
4313
4327
if ( superType !== unknownType ) {
4314
- return resolveCall ( node , getSignaturesOfType ( superType , SignatureKind . Construct ) ) ;
4328
+ return resolveCall ( node , getSignaturesOfType ( superType , SignatureKind . Construct ) , candidatesOutArray ) ;
4315
4329
}
4316
4330
return resolveUntypedCall ( node ) ;
4317
4331
}
@@ -4359,10 +4373,10 @@ module ts {
4359
4373
}
4360
4374
return resolveErrorCall ( node ) ;
4361
4375
}
4362
- return resolveCall ( node , callSignatures ) ;
4376
+ return resolveCall ( node , callSignatures , candidatesOutArray ) ;
4363
4377
}
4364
4378
4365
- function resolveNewExpression ( node : NewExpression ) : Signature {
4379
+ function resolveNewExpression ( node : NewExpression , candidatesOutArray : Signature [ ] ) : Signature {
4366
4380
var expressionType = checkExpression ( node . func ) ;
4367
4381
if ( expressionType === unknownType ) {
4368
4382
// Another error has already been reported
@@ -4397,7 +4411,7 @@ module ts {
4397
4411
// that the user will not add any.
4398
4412
var constructSignatures = getSignaturesOfType ( expressionType , SignatureKind . Construct ) ;
4399
4413
if ( constructSignatures . length ) {
4400
- return resolveCall ( node , constructSignatures ) ;
4414
+ return resolveCall ( node , constructSignatures , candidatesOutArray ) ;
4401
4415
}
4402
4416
4403
4417
// If ConstructExpr's apparent type is an object type with no construct signatures but
@@ -4406,7 +4420,7 @@ module ts {
4406
4420
// operation is Any.
4407
4421
var callSignatures = getSignaturesOfType ( expressionType , SignatureKind . Call ) ;
4408
4422
if ( callSignatures . length ) {
4409
- var signature = resolveCall ( node , callSignatures ) ;
4423
+ var signature = resolveCall ( node , callSignatures , candidatesOutArray ) ;
4410
4424
if ( getReturnTypeOfSignature ( signature ) !== voidType ) {
4411
4425
error ( node , Diagnostics . Only_a_void_function_can_be_called_with_the_new_keyword ) ;
4412
4426
}
@@ -4417,11 +4431,15 @@ module ts {
4417
4431
return resolveErrorCall ( node ) ;
4418
4432
}
4419
4433
4420
- function getResolvedSignature ( node : CallExpression ) : Signature {
4434
+ // candidatesOutArray is passed by signature help in the language service, and collectCandidates
4435
+ // must fill it up with the appropriate candidate signatures
4436
+ function getResolvedSignature ( node : CallExpression , candidatesOutArray ?: Signature [ ] ) : Signature {
4421
4437
var links = getNodeLinks ( node ) ;
4422
4438
if ( ! links . resolvedSignature ) {
4423
4439
links . resolvedSignature = anySignature ;
4424
- links . resolvedSignature = node . kind === SyntaxKind . CallExpression ? resolveCallExpression ( node ) : resolveNewExpression ( node ) ;
4440
+ links . resolvedSignature = node . kind === SyntaxKind . CallExpression
4441
+ ? resolveCallExpression ( node , candidatesOutArray )
4442
+ : resolveNewExpression ( node , candidatesOutArray ) ;
4425
4443
}
4426
4444
return links . resolvedSignature ;
4427
4445
}
0 commit comments