@@ -136,13 +136,15 @@ private module Cached {
136136 newtype TParameterPosition =
137137 TPositionalParameterPosition ( int i ) { i = any ( Parameter p ) .getPosition ( ) } or
138138 TThisParameterPosition ( ) or
139- TImplicitCapturedParameterPosition ( LocalScopeVariable v ) { capturedWithFlowIn ( v ) }
139+ TImplicitCapturedParameterPosition ( LocalScopeVariable v ) { capturedWithFlowIn ( v ) } or
140+ TDelegateSelfParameterPosition ( )
140141
141142 cached
142143 newtype TArgumentPosition =
143144 TPositionalArgumentPosition ( int i ) { i = any ( Parameter p ) .getPosition ( ) } or
144145 TQualifierArgumentPosition ( ) or
145- TImplicitCapturedArgumentPosition ( LocalScopeVariable v ) { capturedWithFlowIn ( v ) }
146+ TImplicitCapturedArgumentPosition ( LocalScopeVariable v ) { capturedWithFlowIn ( v ) } or
147+ TDelegateSelfArgumentPosition ( )
146148}
147149
148150import Cached
@@ -480,6 +482,14 @@ class ParameterPosition extends TParameterPosition {
480482 this = TImplicitCapturedParameterPosition ( v )
481483 }
482484
485+ /**
486+ * Holds if this position represents a reference to a delegate itself.
487+ *
488+ * Used for tracking flow through captured variables and for improving
489+ * delegate dispatch.
490+ */
491+ predicate isDelegateSelf ( ) { this = TDelegateSelfParameterPosition ( ) }
492+
483493 /** Gets a textual representation of this position. */
484494 string toString ( ) {
485495 result = "position " + this .getPosition ( )
@@ -489,6 +499,9 @@ class ParameterPosition extends TParameterPosition {
489499 exists ( LocalScopeVariable v |
490500 this .isImplicitCapturedParameterPosition ( v ) and result = "captured " + v
491501 )
502+ or
503+ this .isDelegateSelf ( ) and
504+ result = "delegate self"
492505 }
493506}
494507
@@ -505,6 +518,14 @@ class ArgumentPosition extends TArgumentPosition {
505518 this = TImplicitCapturedArgumentPosition ( v )
506519 }
507520
521+ /**
522+ * Holds if this position represents a reference to a delegate itself.
523+ *
524+ * Used for tracking flow through captured variables and for improving
525+ * delegate dispatch.
526+ */
527+ predicate isDelegateSelf ( ) { this = TDelegateSelfArgumentPosition ( ) }
528+
508529 /** Gets a textual representation of this position. */
509530 string toString ( ) {
510531 result = "position " + this .getPosition ( )
@@ -514,6 +535,9 @@ class ArgumentPosition extends TArgumentPosition {
514535 exists ( LocalScopeVariable v |
515536 this .isImplicitCapturedArgumentPosition ( v ) and result = "captured " + v
516537 )
538+ or
539+ this .isDelegateSelf ( ) and
540+ result = "delegate self"
517541 }
518542}
519543
@@ -527,4 +551,6 @@ predicate parameterMatch(ParameterPosition ppos, ArgumentPosition apos) {
527551 ppos .isImplicitCapturedParameterPosition ( v ) and
528552 apos .isImplicitCapturedArgumentPosition ( v )
529553 )
554+ or
555+ ppos .isDelegateSelf ( ) and apos .isDelegateSelf ( )
530556}
0 commit comments