Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rubysrc2cpg] Fixed Duplicate Do-Blocks Due to Side-Effect #3720

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,6 @@ class AstCreator(
columnEnd(ctx).head
)

blockMethodAsts.foreach { ast =>
ast.root match
case Some(_: NewMethod) => blockMethods.addOne(ast)
case _ =>
}

blockMethodAsts :+ blockMethodAsts
.flatMap(_.nodes)
.collectFirst { case methodRefNode: NewMethodRef =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,17 @@ class DoBlockTest extends RubyCode2CpgFixture {
}
}

"a do-block function wrapped within a chained invocation inside of a call argument" should {
val cpg = code("OpenStruct.new(obj.map { |key, val| [key, to_recursive_ostruct(val)] }.to_h)")

"create a do-block method named from the surrounding function" in {
val mapMethod :: _ = cpg.method.name("map.*").l: @unchecked
mapMethod.name should startWith("map")
mapMethod.parameter.size shouldBe 2
val k :: v :: _ = mapMethod.parameter.l: @unchecked
k.name shouldBe "key"
v.name shouldBe "val"
}
}

}