@@ -297,16 +297,46 @@ DataFlowCallable nodeGetEnclosingCallable(Node node) {
297297}
298298
299299private newtype TDataFlowType =
300- TTodoDataFlowType ( ) or
301- TTodoDataFlowType2 ( ) // Add a dummy value to prevent bad functionality-induced joins arising from a type of size 1.
300+ TFunctionType ( Function f ) or
301+ TAnyType ( )
302302
303303class DataFlowType extends TDataFlowType {
304- string toString ( ) { result = "" }
304+ string toString ( ) {
305+ this instanceof TFunctionType and
306+ result =
307+ "TFunctionType(" + this .asFunction ( ) .toString ( ) + ") at line " +
308+ this .asFunction ( ) .getLocation ( ) .getStartLine ( )
309+ or
310+ this instanceof TAnyType and result = "TAnyType"
311+ }
312+
313+ Function asFunction ( ) { this = TFunctionType ( result ) }
305314}
306315
307- predicate typeStrongerThan ( DataFlowType t1 , DataFlowType t2 ) { none ( ) }
316+ /**
317+ * Holds if `t1` is strictly stronger than `t2`.
318+ */
319+ predicate typeStrongerThan ( DataFlowType t1 , DataFlowType t2 ) {
320+ t1 instanceof TFunctionType and t2 = TAnyType ( )
321+ }
322+
323+ private DataFlowType getPreciseType ( Node node ) {
324+ exists ( Function f |
325+ ( node = TValueNode ( f ) or node = TFunctionSelfReferenceNode ( f ) ) and
326+ result = TFunctionType ( f )
327+ )
328+ or
329+ result = getPreciseType ( node .getImmediatePredecessor ( ) )
330+ or
331+ result = getPreciseType ( node .( PostUpdateNode ) .getPreUpdateNode ( ) )
332+ }
308333
309- DataFlowType getNodeType ( Node node ) { result = TTodoDataFlowType ( ) and exists ( node ) }
334+ DataFlowType getNodeType ( Node node ) {
335+ result = getPreciseType ( node )
336+ or
337+ not exists ( getPreciseType ( node ) ) and
338+ result = TAnyType ( )
339+ }
310340
311341predicate nodeIsHidden ( Node node ) {
312342 DataFlow:: PathNode:: shouldNodeBeHidden ( node )
@@ -341,10 +371,16 @@ predicate neverSkipInPathGraph(Node node) {
341371 node .asExpr ( ) instanceof VarRef
342372}
343373
344- string ppReprType ( DataFlowType t ) { none ( ) }
374+ string ppReprType ( DataFlowType t ) { result = t . toString ( ) }
345375
346376pragma [ inline]
347- predicate compatibleTypes ( DataFlowType t1 , DataFlowType t2 ) { any ( ) }
377+ predicate compatibleTypes ( DataFlowType t1 , DataFlowType t2 ) {
378+ t1 = t2
379+ or
380+ t1 instanceof TAnyType and exists ( t2 )
381+ or
382+ t2 instanceof TAnyType and exists ( t1 )
383+ }
348384
349385predicate forceHighPrecision ( Content c ) { none ( ) }
350386
0 commit comments