@@ -8,10 +8,16 @@ module TypeResolution {
88
99 predicate trackType = TypeFlow:: TrackNode< TypeDefinition > :: track / 1 ;
1010
11- Node trackFunctionType ( Function fun ) {
11+ /**
12+ * Gets a node that has `fun` as an underlying type.
13+ *
14+ * We track through underlying types as an approximate way to handle calls to a type
15+ * that is a union/intersection involving functions.
16+ */
17+ Node trackUnderlyingFunctionType ( Function fun ) {
1218 result = fun
1319 or
14- exists ( Node mid | mid = trackFunctionType ( fun ) |
20+ exists ( Node mid | mid = trackUnderlyingFunctionType ( fun ) |
1521 TypeFlow:: step ( mid , result )
1622 or
1723 UnderlyingTypes:: underlyingTypeStep ( mid , result )
@@ -138,7 +144,7 @@ module TypeResolution {
138144 or
139145 valueHasType ( call .getCallee ( ) , trackFunctionValue ( target ) )
140146 or
141- valueHasType ( call .getCallee ( ) , trackFunctionType ( target ) ) and
147+ valueHasType ( call .getCallee ( ) , trackUnderlyingFunctionType ( target ) ) and
142148 (
143149 call instanceof NewExpr and
144150 target = any ( ConstructorTypeExpr t ) .getFunction ( )
@@ -165,7 +171,7 @@ module TypeResolution {
165171 or
166172 not exists ( func .getReturnTypeAnnotation ( ) ) and
167173 exists ( Function functionType |
168- contextualType ( func , trackFunctionType ( functionType ) ) and
174+ contextualType ( func , trackUnderlyingFunctionType ( functionType ) ) and
169175 returnType = functionType .getReturnTypeAnnotation ( )
170176 )
171177 }
@@ -270,7 +276,7 @@ module TypeResolution {
270276 or
271277 // Contextual typing for parameters
272278 exists ( Function lambda , Function functionType , int i |
273- contextualType ( lambda , trackFunctionType ( functionType ) )
279+ contextualType ( lambda , trackUnderlyingFunctionType ( functionType ) )
274280 or
275281 exists ( InterfaceDefinition interface |
276282 contextualType ( lambda , trackType ( interface ) ) and
0 commit comments