joern
joern copied to clipboard
Import node handling for package imports whose package name is different than the folder name
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