@@ -480,7 +480,11 @@ module Public {
480
480
class CallNode extends ExprNode {
481
481
override CallExpr expr ;
482
482
483
- /** Gets the declared target of this call */
483
+ /**
484
+ * Gets the declared target of this call, if it exists.
485
+ *
486
+ * This doesn't exist when a function is called via a variable.
487
+ */
484
488
Function getTarget ( ) { result = expr .getTarget ( ) }
485
489
486
490
private DataFlow:: Node getACalleeSource ( ) { result = getACalleeSource ( this ) }
@@ -637,14 +641,41 @@ module Public {
637
641
/** Gets a result of this call. */
638
642
Node getAResult ( ) { result = this .getResult ( _) }
639
643
640
- /** Gets the data flow node corresponding to the receiver of this call, if any. */
644
+ /**
645
+ * Gets the data flow node corresponding to the receiver of this call, if any.
646
+ *
647
+ * When a method value is assigned to a variable then when it is called it
648
+ * looks like a function call, as in the following example.
649
+ *
650
+ * ```go
651
+ * file, _ := os.Open("test.txt")
652
+ * f := file.Close
653
+ * f()
654
+ * ```
655
+ *
656
+ * In this case we use local flow to try to find the receiver (`file` in
657
+ * the above example).
658
+ */
641
659
Node getReceiver ( ) { result = this .getACalleeSource ( ) .( MethodReadNode ) .getReceiver ( ) }
642
660
643
661
/** Holds if this call has an ellipsis after its last argument. */
644
662
predicate hasEllipsis ( ) { expr .hasEllipsis ( ) }
645
663
}
646
664
647
- /** A data flow node that represents a call to a method. */
665
+ /**
666
+ * A data flow node that represents a direct call to a method.
667
+ *
668
+ * When a method value is assigned to a variable then when it is called it
669
+ * syntactically looks like a function call, as in the following example.
670
+ *
671
+ * ```go
672
+ * file, _ := os.Open("test.txt")
673
+ * f := file.Close
674
+ * f()
675
+ * ```
676
+ *
677
+ * In this case it will not be considered a `MethodCallNode`.
678
+ */
648
679
class MethodCallNode extends CallNode {
649
680
MethodCallNode ( ) { expr .getTarget ( ) instanceof Method }
650
681
0 commit comments