@@ -8,10 +8,16 @@ module TypeResolution {
8
8
9
9
predicate trackType = TypeFlow:: TrackNode< TypeDefinition > :: track / 1 ;
10
10
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 ) {
12
18
result = fun
13
19
or
14
- exists ( Node mid | mid = trackFunctionType ( fun ) |
20
+ exists ( Node mid | mid = trackUnderlyingFunctionType ( fun ) |
15
21
TypeFlow:: step ( mid , result )
16
22
or
17
23
UnderlyingTypes:: underlyingTypeStep ( mid , result )
@@ -138,7 +144,7 @@ module TypeResolution {
138
144
or
139
145
valueHasType ( call .getCallee ( ) , trackFunctionValue ( target ) )
140
146
or
141
- valueHasType ( call .getCallee ( ) , trackFunctionType ( target ) ) and
147
+ valueHasType ( call .getCallee ( ) , trackUnderlyingFunctionType ( target ) ) and
142
148
(
143
149
call instanceof NewExpr and
144
150
target = any ( ConstructorTypeExpr t ) .getFunction ( )
@@ -165,7 +171,7 @@ module TypeResolution {
165
171
or
166
172
not exists ( func .getReturnTypeAnnotation ( ) ) and
167
173
exists ( Function functionType |
168
- contextualType ( func , trackFunctionType ( functionType ) ) and
174
+ contextualType ( func , trackUnderlyingFunctionType ( functionType ) ) and
169
175
returnType = functionType .getReturnTypeAnnotation ( )
170
176
)
171
177
}
@@ -270,7 +276,7 @@ module TypeResolution {
270
276
or
271
277
// Contextual typing for parameters
272
278
exists ( Function lambda , Function functionType , int i |
273
- contextualType ( lambda , trackFunctionType ( functionType ) )
279
+ contextualType ( lambda , trackUnderlyingFunctionType ( functionType ) )
274
280
or
275
281
exists ( InterfaceDefinition interface |
276
282
contextualType ( lambda , trackType ( interface ) ) and
0 commit comments