@@ -4088,19 +4088,6 @@ module ts {
40884088 return getSignatureInstantiation ( signature , getInferredTypes ( context ) ) ;
40894089 }
40904090
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-
41044091 function inferTypeArguments ( signature : Signature , args : Expression [ ] , excludeArgument ?: boolean [ ] ) : Type [ ] {
41054092 var typeParameters = signature . typeParameters ;
41064093 var context = createInferenceContext ( typeParameters ) ;
@@ -4109,15 +4096,15 @@ module ts {
41094096 for ( var i = 0 ; i < args . length ; i ++ ) {
41104097 if ( ! excludeArgument || excludeArgument [ i ] === undefined ) {
41114098 var parameterType = getTypeAtPosition ( signature , i ) ;
4112- inferTypes ( context , inferentiallyTypeExpession ( args [ i ] , parameterType , mapper ) , parameterType ) ;
4099+ inferTypes ( context , checkExpressionWithContextualType ( args [ i ] , parameterType , mapper ) , parameterType ) ;
41134100 }
41144101 }
41154102 // Next, infer from those context sensitive arguments that are no longer excluded
41164103 if ( excludeArgument ) {
41174104 for ( var i = 0 ; i < args . length ; i ++ ) {
41184105 if ( excludeArgument [ i ] === false ) {
41194106 var parameterType = getTypeAtPosition ( signature , i ) ;
4120- inferTypes ( context , inferentiallyTypeExpession ( args [ i ] , parameterType , mapper ) , parameterType ) ;
4107+ inferTypes ( context , checkExpressionWithContextualType ( args [ i ] , parameterType , mapper ) , parameterType ) ;
41214108 }
41224109 }
41234110 }
@@ -4852,6 +4839,23 @@ module ts {
48524839 // have the wildcard function type; this form of type check is used during overload resolution to exclude
48534840 // contextually typed function and arrow expressions in the initial phase.
48544841 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 {
48554859 switch ( node . kind ) {
48564860 case SyntaxKind . Identifier :
48574861 return checkIdentifier ( < Identifier > node ) ;
0 commit comments