Skip to content

Commit 48d26b5

Browse files
Fix pattern cast line numbers (#5228)
1 parent ee19e27 commit 48d26b5

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

joern-cli/frontends/javasrc2cpg/src/main/scala/io/joern/javasrc2cpg/astcreation/expressions/AstForPatternExpressionsCreator.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ trait AstForPatternExpressionsCreator { this: AstCreator =>
190190
newOperatorCallNode(
191191
Operators.cast,
192192
s"(${castType.code}) ${initializerAst.rootCodeOrEmpty}",
193-
Option(patternType)
193+
Option(patternType),
194+
line(patternExpr),
195+
column(patternExpr)
194196
)
195197
callAst(castNode, Ast(castType) :: initializerAst :: Nil)
196198
}

joern-cli/frontends/javasrc2cpg/src/test/scala/io/joern/javasrc2cpg/querying/PatternExprTests.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,8 @@ class PatternExprTests extends JavaSrcCode2CpgFixture {
21732173
oCast.name shouldBe Operators.cast
21742174
oCast.code shouldBe "(Box) o"
21752175
oCast.typeFullName shouldBe "box.Box"
2176+
oCast.lineNumber shouldBe Some(9)
2177+
oCast.columnNumber shouldBe Some(12)
21762178

21772179
inside(oCast.argument.l) { case List(boxType: TypeRef, oIdentifier: Identifier) =>
21782180
boxType.typeFullName shouldBe "box.Box"

0 commit comments

Comments
 (0)