@@ -114,11 +114,22 @@ module TypeResolution {
114114 )
115115 }
116116
117- private predicate contextualType ( Node value , Node contextualType ) {
117+ predicate valueHasContextualType ( Node value , Node type ) {
118118 exists ( InvokeExpr call , Function target , int i |
119119 callTarget ( call , target ) and
120120 value = call .getArgument ( i ) and
121- contextualType = target .getParameter ( i ) .getTypeAnnotation ( )
121+ type = target .getParameter ( i ) .getTypeAnnotation ( )
122+ )
123+ or
124+ exists ( VariableDeclarator decl |
125+ value = decl .getInit ( ) and
126+ type = decl .getTypeAnnotation ( )
127+ )
128+ or
129+ exists ( Function functionValue , Function functionType |
130+ valueHasContextualType ( functionValue , trackFunctionType ( functionType ) ) and
131+ value = functionValue .getAReturnedExpr ( ) and
132+ type = functionType .getReturnTypeAnnotation ( )
122133 )
123134 }
124135
@@ -154,10 +165,10 @@ module TypeResolution {
154165 or
155166 // Contextual typing for parameters
156167 exists ( Function lambda , Function functionType , int i |
157- contextualType ( lambda , trackFunctionType ( functionType ) )
168+ valueHasContextualType ( lambda , trackFunctionType ( functionType ) )
158169 or
159170 exists ( InterfaceDefinition interface |
160- contextualType ( lambda , trackType ( interface ) ) and
171+ valueHasContextualType ( lambda , trackType ( interface ) ) and
161172 functionType = interface .getACallSignature ( ) .getBody ( )
162173 )
163174 |
0 commit comments