File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
joern-cli/frontends/rubysrc2cpg/src
main/scala/io/joern/rubysrc2cpg/astcreation
test/scala/io/joern/rubysrc2cpg/querying Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -237,7 +237,7 @@ trait AstForFunctionsCreator(implicit withSchemaValidation: ValidationMode) { th
237237 case i : NewIdentifier if capturedNodes.map(_.name).contains(i.name) => i
238238 }
239239 // Copy AST block detaching the REF nodes between parent locals/params and identifiers, with the closures' one
240- val capturedBlockAst = baseStmtBlockAst.copy(refEdges = baseStmtBlockAst.refEdges.filterNot {
240+ val capturedBlockAst = baseStmtBlockAst.copy(refEdges = baseStmtBlockAst.refEdges.filter {
241241 case AstEdge (_ : NewIdentifier , dst : DeclarationNew ) => capturedNodes.contains(dst)
242242 case _ => false
243243 })
Original file line number Diff line number Diff line change @@ -544,4 +544,26 @@ class DoBlockTests extends RubyCode2CpgFixture {
544544 backRefCall.lineNumber shouldBe Option (3 )
545545 backRefCall.columnNumber shouldBe Option (29 )
546546 }
547+
548+ " A `self` reference in a lambda" should {
549+ val cpg = code(
550+ """
551+ |foo("something") { |x| send x }
552+ |""" .stripMargin)
553+
554+ " not result in `self` identifiers with multiple refOut edges" in {
555+ inside(cpg.method.isLambda.ast.fieldAccess.argument.isIdentifier.distinct.nameExact(RubyDefines .Self ).l) {
556+ case (identifier : Identifier ) :: Nil =>
557+ inside(identifier.refOut.l) {
558+ case (local : Local ) :: Nil =>
559+ local.name shouldBe " self"
560+ local.closureBindingId shouldBe Some (" Test0.rb:<main>.<lambda>0.self" )
561+ case xs =>
562+ fail(s " Expected a single local, got [ ${xs.code.mkString(" ," )}] " )
563+ }
564+ case Nil =>
565+ fail(s " Expected `self` identifiers, got none " )
566+ }
567+ }
568+ }
547569}
You can’t perform that action at this time.
0 commit comments