Skip to content

Commit 217d307

Browse files
[kotlin2cpg] explicit ordering for throw statement ast (#5853)
1 parent 8e7067d commit 217d307

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

joern-cli/frontends/kotlin2cpg/src/main/scala/io/joern/kotlin2cpg/ast/AstForStatementsCreator.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import io.joern.x2cpg.ValidationMode
77
import io.shiftleft.codepropertygraph.generated.ControlStructureTypes
88
import io.shiftleft.codepropertygraph.generated.DispatchTypes
99
import io.shiftleft.codepropertygraph.generated.Operators
10+
import io.shiftleft.codepropertygraph.generated.nodes.AstNodeNew
1011
import io.shiftleft.codepropertygraph.generated.nodes.NewLocal
1112
import org.jetbrains.kotlin.psi.KtAnnotationEntry
1213
import org.jetbrains.kotlin.psi.KtBlockExpression
@@ -536,7 +537,10 @@ trait AstForStatementsCreator(implicit withSchemaValidation: ValidationMode) {
536537
annotations: Seq[KtAnnotationEntry] = Seq()
537538
): Ast = {
538539
val thrownValue = astsForExpression(expr.getThrownExpression, None)
539-
val node = controlStructureNode(expr, ControlStructureTypes.THROW, expr.getText)
540+
thrownValue.headOption.flatMap(_.root).collect { case node: AstNodeNew =>
541+
node.order(1)
542+
}
543+
val node = controlStructureNode(expr, ControlStructureTypes.THROW, code(expr))
540544
Ast(node).withChildren(thrownValue)
541545
}
542546

joern-cli/frontends/kotlin2cpg/src/test/scala/io/joern/kotlin2cpg/querying/ControlStructureTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ class ControlStructureTests extends KotlinCode2CpgFixture(withOssDataflow = fals
232232
// RuntimeException.<init>(tmp, "boom")
233233
// }
234234
val List(throwBlock: Block) = throwNode.astChildren.l
235+
throwBlock.order shouldBe 1
235236
inside(throwBlock.astChildren.isCall.sortBy(_.name).l) { case List(init: Call, assignment: Call) =>
236237
// Not really testing ctor generation, just a simple check that it does exist and has expected values
237238
assignment.name shouldBe "<operator>.assignment"

0 commit comments

Comments
 (0)