@@ -4088,19 +4088,6 @@ module ts {
4088
4088
return getSignatureInstantiation ( signature , getInferredTypes ( context ) ) ;
4089
4089
}
4090
4090
4091
- // Inferentially type an expression by a contextual parameter type (section 4.12.2 in TypeScript spec)
4092
- function inferentiallyTypeExpession ( expr : Expression , contextualType : Type , contextualMapper : TypeMapper ) : Type {
4093
- var type = checkExpressionWithContextualType ( expr , contextualType , contextualMapper ) ;
4094
- var signature = getSingleCallSignature ( type ) ;
4095
- if ( signature && signature . typeParameters ) {
4096
- var contextualSignature = getSingleCallSignature ( contextualType ) ;
4097
- if ( contextualSignature && ! contextualSignature . typeParameters ) {
4098
- type = getOrCreateTypeFromSignature ( instantiateSignatureInContextOf ( signature , contextualSignature , contextualMapper ) ) ;
4099
- }
4100
- }
4101
- return type ;
4102
- }
4103
-
4104
4091
function inferTypeArguments ( signature : Signature , args : Expression [ ] , excludeArgument ?: boolean [ ] ) : Type [ ] {
4105
4092
var typeParameters = signature . typeParameters ;
4106
4093
var context = createInferenceContext ( typeParameters ) ;
@@ -4109,15 +4096,15 @@ module ts {
4109
4096
for ( var i = 0 ; i < args . length ; i ++ ) {
4110
4097
if ( ! excludeArgument || excludeArgument [ i ] === undefined ) {
4111
4098
var parameterType = getTypeAtPosition ( signature , i ) ;
4112
- inferTypes ( context , inferentiallyTypeExpession ( args [ i ] , parameterType , mapper ) , parameterType ) ;
4099
+ inferTypes ( context , checkExpressionWithContextualType ( args [ i ] , parameterType , mapper ) , parameterType ) ;
4113
4100
}
4114
4101
}
4115
4102
// Next, infer from those context sensitive arguments that are no longer excluded
4116
4103
if ( excludeArgument ) {
4117
4104
for ( var i = 0 ; i < args . length ; i ++ ) {
4118
4105
if ( excludeArgument [ i ] === false ) {
4119
4106
var parameterType = getTypeAtPosition ( signature , i ) ;
4120
- inferTypes ( context , inferentiallyTypeExpession ( args [ i ] , parameterType , mapper ) , parameterType ) ;
4107
+ inferTypes ( context , checkExpressionWithContextualType ( args [ i ] , parameterType , mapper ) , parameterType ) ;
4121
4108
}
4122
4109
}
4123
4110
}
@@ -4852,6 +4839,23 @@ module ts {
4852
4839
// have the wildcard function type; this form of type check is used during overload resolution to exclude
4853
4840
// contextually typed function and arrow expressions in the initial phase.
4854
4841
function checkExpression ( node : Expression , contextualMapper ?: TypeMapper ) : Type {
4842
+ var type = checkExpressionNode ( node , contextualMapper ) ;
4843
+ if ( contextualMapper && contextualMapper !== identityMapper ) {
4844
+ var signature = getSingleCallSignature ( type ) ;
4845
+ if ( signature && signature . typeParameters ) {
4846
+ var contextualType = getContextualType ( node ) ;
4847
+ if ( contextualType ) {
4848
+ var contextualSignature = getSingleCallSignature ( contextualType ) ;
4849
+ if ( contextualSignature && ! contextualSignature . typeParameters ) {
4850
+ type = getOrCreateTypeFromSignature ( instantiateSignatureInContextOf ( signature , contextualSignature , contextualMapper ) ) ;
4851
+ }
4852
+ }
4853
+ }
4854
+ }
4855
+ return type ;
4856
+ }
4857
+
4858
+ function checkExpressionNode ( node : Expression , contextualMapper : TypeMapper ) : Type {
4855
4859
switch ( node . kind ) {
4856
4860
case SyntaxKind . Identifier :
4857
4861
return checkIdentifier ( < Identifier > node ) ;
0 commit comments