@@ -474,7 +474,11 @@ module Public {
474
474
class CallNode extends ExprNode {
475
475
override CallExpr expr ;
476
476
477
- /** Gets the declared target of this call */
477
+ /**
478
+ * Gets the declared target of this call, if it exists.
479
+ *
480
+ * This doesn't exist when a function is called via a variable.
481
+ */
478
482
Function getTarget ( ) { result = expr .getTarget ( ) }
479
483
480
484
private DataFlow:: Node getACalleeSource ( ) { result = getACalleeSource ( this ) }
@@ -622,18 +626,42 @@ module Public {
622
626
/** Gets a result of this call. */
623
627
Node getAResult ( ) { result = this .getResult ( _) }
624
628
625
- /** Gets the data flow node corresponding to the receiver of this call, if any. */
629
+ /**
630
+ * Gets the data flow node corresponding to the receiver of this call, if any.
631
+ *
632
+ * When a method value is assigned to a variable then when it is called it
633
+ * looks like a function call, as in the following example.
634
+ * ```go
635
+ * file, _ := os.Open("test.txt")
636
+ * f := file.Close
637
+ * f()
638
+ * ```
639
+ * In this case we use local flow to try to find the receiver (`file` in
640
+ * the above example).
641
+ */
626
642
Node getReceiver ( ) { result = this .getACalleeSource ( ) .( MethodReadNode ) .getReceiver ( ) }
627
643
628
644
/** Holds if this call has an ellipsis after its last argument. */
629
645
predicate hasEllipsis ( ) { expr .hasEllipsis ( ) }
630
646
}
631
647
632
- /** A data flow node that represents a call to a method. */
648
+ /**
649
+ * A data flow node that represents a call to a method.
650
+ *
651
+ * When a method value is assigned to a variable then when it is called it
652
+ * syntactically looks like a function call, as in the following example.
653
+ * ```go
654
+ * file, _ := os.Open("test.txt")
655
+ * f := file.Close
656
+ * f()
657
+ * ```
658
+ * In this case we use local flow to see whether a method is assigned to the
659
+ * function.
660
+ */
633
661
class MethodCallNode extends CallNode {
634
662
MethodCallNode ( ) { getACalleeSource ( this ) instanceof MethodReadNode }
635
663
636
- override Method getTarget ( ) { result = getACalleeSource ( this ) . ( MethodReadNode ) . getMethod ( ) }
664
+ override Method getTarget ( ) { result = expr . getTarget ( ) }
637
665
638
666
override MethodDecl getACallee ( ) { result = super .getACallee ( ) }
639
667
}
0 commit comments