Skip to content

Commit

Permalink
Tested code for the recreated spans
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBakerEffendi committed Mar 20, 2024
1 parent b611750 commit 77cc589
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -825,16 +825,18 @@ class RubyNodeCreator extends RubyParserBaseVisitor[RubyNode] {
val loweredMethods = classBodyStmts.collect { case alias: AliasStatement =>
methodParamMap.get(alias.oldName) match {
case Some(aliasingMethodParams) =>
val argsCode = aliasingMethodParams.map(_.text).mkString(", ")
val callCode = s"${alias.oldName}($argsCode)"
MethodDeclaration(
alias.newName,
aliasingMethodParams,
StatementList(
SimpleCall(
SimpleIdentifier(None)(alias.span.spanStart(alias.oldName)),
aliasingMethodParams.map { x => SimpleIdentifier(None)(alias.span.spanStart(x.span.text)) }
)(alias.span) :: Nil
)(alias.span)
)(alias.span)
)(alias.span.spanStart(callCode)) :: Nil
)(alias.span.spanStart(callCode))
)(alias.span.spanStart(s"def ${alias.newName}($argsCode)"))
case None =>
logger.warn(
s"Unable to correctly lower aliased method ${alias.oldName}, the result will be in degraded parameter/argument flows"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,12 @@ class MethodTests extends RubyCode2CpgFixture {

xeq.parameter.name.l shouldBe bar.parameter.name.l
// bar forwards parameters to a call to the aliased method
bar.call.name("x=").argument.isIdentifier.name.head shouldBe "z"
inside(bar.call.name("x=").l) {
case barCall :: Nil =>
barCall.argument.isIdentifier.name.head shouldBe "z"
barCall.code shouldBe "x=(z)"
case xs => fail(s"Expected a single call to `bar=`, instead got [${xs.code.mkString(",")}]")
}
case xs => fail(s"Expected a three virtual methods under `Foo`, instead got [${xs.code.mkString(",")}]")
}
case xs => fail(s"Expected a single type decl for `Foo`, instead got [${xs.code.mkString(",")}]")
Expand Down

0 comments on commit 77cc589

Please sign in to comment.