@@ -230,6 +230,8 @@ module LocalFlow {
230230 or
231231 p .( KeywordParameter ) .getDefaultValue ( ) = nodeFrom .asExpr ( ) .getExpr ( )
232232 )
233+ or
234+ nodeTo .( BlockArgumentNode ) .getParameterNode ( true ) = nodeFrom
233235 }
234236}
235237
@@ -497,6 +499,9 @@ private module Cached {
497499 TSelfParameterNode ( MethodBase m ) or
498500 TLambdaSelfReferenceNode ( Callable c ) { lambdaCreationExpr ( _, _, c ) } or
499501 TBlockParameterNode ( MethodBase m ) or
502+ TBlockArgumentNode ( CfgNodes:: ExprNodes:: CallCfgNode yield ) {
503+ yield = any ( BlockParameterNode b ) .getAYieldCall ( )
504+ } or
500505 TSynthHashSplatParameterNode ( DataFlowCallable c ) {
501506 isParameterNode ( _, c , any ( ParameterPosition p | p .isKeyword ( _) ) )
502507 } or
@@ -645,6 +650,8 @@ private module Cached {
645650 isStoreTargetNode ( n )
646651 or
647652 TypeTrackingInput:: loadStep ( _, n , _)
653+ or
654+ n instanceof BlockArgumentNode
648655 }
649656
650657 cached
@@ -770,6 +777,8 @@ predicate nodeIsHidden(Node n) {
770777 n instanceof LambdaSelfReferenceNode
771778 or
772779 n instanceof CaptureNode
780+ or
781+ n instanceof BlockArgumentNode
773782}
774783
775784/** An SSA definition, viewed as a node in a data flow graph. */
@@ -1277,18 +1286,36 @@ module ArgumentNodes {
12771286 }
12781287 }
12791288
1280- class BlockParameterArgumentNode extends BlockParameterNode , ArgumentNode {
1281- BlockParameterArgumentNode ( ) { exists ( this .getAYieldCall ( ) ) }
1289+ class BlockArgumentNode extends NodeImpl , ArgumentNode , TBlockArgumentNode {
1290+ CfgNodes:: ExprNodes:: CallCfgNode yield ;
1291+
1292+ BlockArgumentNode ( ) { this = TBlockArgumentNode ( yield ) }
1293+
1294+ CfgNodes:: ExprNodes:: CallCfgNode getYieldCall ( ) { result = yield }
1295+
1296+ pragma [ nomagic]
1297+ BlockParameterNode getParameterNode ( boolean inSameScope ) {
1298+ result .getAYieldCall ( ) = yield and
1299+ if nodeGetEnclosingCallable ( this ) = nodeGetEnclosingCallable ( result )
1300+ then inSameScope = true
1301+ else inSameScope = false
1302+ }
12821303
12831304 // needed for variable capture flow
12841305 override predicate sourceArgumentOf ( CfgNodes:: ExprNodes:: CallCfgNode call , ArgumentPosition pos ) {
1285- call = this . getAYieldCall ( ) and
1306+ call = yield and
12861307 pos .isLambdaSelf ( )
12871308 }
12881309
12891310 override predicate argumentOf ( DataFlowCall call , ArgumentPosition pos ) {
12901311 this .sourceArgumentOf ( call .asCall ( ) , pos )
12911312 }
1313+
1314+ override CfgScope getCfgScope ( ) { result = yield .getScope ( ) }
1315+
1316+ override Location getLocationImpl ( ) { result = yield .getLocation ( ) }
1317+
1318+ override string toStringImpl ( ) { result = "yield block argument" }
12921319 }
12931320
12941321 private class SummaryArgumentNode extends FlowSummaryNode , ArgumentNode {
@@ -1699,6 +1726,8 @@ predicate jumpStep(Node pred, Node succ) {
16991726 succ .( FlowSummaryNode ) .getSummaryNode ( ) )
17001727 or
17011728 any ( AdditionalJumpStep s ) .step ( pred , succ )
1729+ or
1730+ succ .( BlockArgumentNode ) .getParameterNode ( false ) = pred
17021731}
17031732
17041733private ContentSet getArrayContent ( int n ) {
@@ -2037,7 +2066,7 @@ private predicate lambdaCallExpr(
20372066 */
20382067predicate lambdaSourceCall ( CfgNodes:: ExprNodes:: CallCfgNode call , LambdaCallKind kind , Node receiver ) {
20392068 kind = TYieldCallKind ( ) and
2040- call = receiver .( BlockParameterNode ) . getAYieldCall ( )
2069+ call = receiver .( BlockArgumentNode ) . getYieldCall ( )
20412070 or
20422071 kind = TLambdaCallKind ( ) and
20432072 lambdaCallExpr ( call , receiver .asExpr ( ) )
0 commit comments