joern icon indicating copy to clipboard operation
joern copied to clipboard

Import node handling for package imports whose package name is different than the folder name

Open pandurangpatil opened this issue 2 years ago • 0 comments

    val cpg = code(
      """
        |module joern.io/sample
        |go 1.18
        |""".stripMargin,
      "go.mod"
    ).moreCode(
      """
        |package fpkg
        |type Sample struct {
        |  Name string
        |}
        |func Woo(a int) int{
        |   return 0
        |}
        |""".stripMargin,
      Seq("lib", "lib.go").mkString(File.separator)
    ).moreCode(
      """
        |package main
        |import "joern.io/sample/lib"
        |func main() {
        |  var a = fpkg.Woo(10)
        |  var b = fpkg.Sample{name: "Pandurang"}
        |  var c = b.Name
        |  var d fpkg.Sample
        |}
        |""".stripMargin,
      "main.go"
    )

In the above example, when IMPORT node gets created while processing main.go, its alias has been set to lib instead of fpkg

pandurangpatil avatar Oct 06 '23 11:10 pandurangpatil