Repository: joernio/joern (scala)

Issue:
Method is showing up as TypeDecl
After importing the c snippet `void doFoo() {}`, `doFoo` is showing up in the list of typeDecls. 

Reproduction steps:
```
workspace.reset
importCode.c.fromString(s"""void doFoo() {}""")
cpg.typeDecl.fullName(".*doFoo.*").l
```

Joern output:
```
joern> workspace.reset
creating workspace directory: /tmp/joern/workspace

joern> importCode.c.fromString(s"""void doFoo() {}""")
Creating project `console5565742761463500487` for code at `/tmp/console5565742761463500487`
[...]
res53: Cpg = io.shiftleft.codepropertygraph.generated.Cpg@70d18b82

joern> cpg.typeDecl.fullName(".*doFoo.*").l
res54: List[TypeDecl] = List(
  TypeDecl(
    id -> 2305843009213694027L,
    aliasTypeFullName -> None,
    astParentFullName -> "/tmp/console5565742761463500487/tmp.c:<global>",
    astParentType -> "METHOD",
    code -> "doFoo",
    columnNumber -> None,
    filename -> "/tmp/console5565742761463500487/tmp.c",
    fullName -> "doFoo",
    inheritsFromTypeFullName -> ArraySeq(),
    isExternal -> false,
    lineNumber -> None,
    name -> "doFoo",
    order -> -1
  )
)
joern> cpg.typeDecl.fullName.p
res57: List[String] = List("doFoo", "ANY", "void")
```

Screenshot:
![image](https://user-images.githubusercontent.com/5180740/154846265-8508f52d-900e-4c49-9290-c99f02843a70.png)

Pull request:
Previously, we created a fake method to store all global method definitions and declarations.
This resulted in the creation of synthetic TypeDecls for them as methods have to be under a TypeDecl.
This PR creates an additional fake global TypeDecl with the before-mentioned fake global method in it.

Fixes: https://github.com/joernio/joern/issues/1033

Patch:
diff --git a/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstCreator.scala b/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstCreator.scala
index e69cd89c913b..4f7fac9f67af 100644
--- a/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstCreator.scala
+++ b/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstCreator.scala
@@ -62,7 +62,23 @@ class AstCreator(
     path: String,
     iASTTranslationUnit: IASTTranslationUnit
   ): Ast = {
-    val allDecls = iASTTranslationUnit.getDeclarations
+    val allDecls      = iASTTranslationUnit.getDeclarations
+    val lineNumber    = allDecls.headOption.flatMap(line)
+    val lineNumberEnd = allDecls.lastOption.flatMap(lineEnd)
+
+    val fakeGlobalTypeDecl = newTypeDecl(
+      name,
+      fullName,
+      filename,
+      name,
+      NodeTypes.NAMESPACE_BLOCK,
+      fullName,
+      1,
+      line = lineNumber,
+      column = lineNumberEnd
+    )
+
+    methodAstParentStack.push(fakeGlobalTypeDecl)
 
     val fakeGlobalMethod =
       NewMethod()
@@ -70,9 +86,9 @@ class AstCreator(
         .code(name)
         .fullName(fullName)
         .filename(path)
-        .lineNumber(allDecls.headOption.flatMap(line))
-        .lineNumberEnd(allDecls.lastOption.flatMap(lineEnd))
-        .astParentType(NodeTypes.NAMESPACE_BLOCK)
+        .lineNumber(lineNumber)
+        .lineNumberEnd(lineNumberEnd)
+        .astParentType(NodeTypes.TYPE_DECL)
         .astParentFullName(fullName)
 
     methodAstParentStack.push(fakeGlobalMethod)
@@ -104,9 +120,11 @@ class AstCreator(
       .typeFullName("ANY")
       .order(2)
 
-    Ast(fakeGlobalMethod)
-      .withChild(Ast(blockNode).withChildren(declsAsts))
-      .withChild(Ast(methodReturn))
+    Ast(fakeGlobalTypeDecl).withChild(
+      Ast(fakeGlobalMethod)
+        .withChild(Ast(blockNode).withChildren(declsAsts))
+        .withChild(Ast(methodReturn))
+    )
   }
 
   private def astForTranslationUnit(iASTTranslationUnit: IASTTranslationUnit): Ast = {
diff --git a/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstForFunctionsCreator.scala b/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstForFunctionsCreator.scala
index b1712cdbc166..42073f8b4674 100644
--- a/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstForFunctionsCreator.scala
+++ b/joern-cli/frontends/c2cpg/src/main/scala/io/joern/c2cpg/astcreation/AstForFunctionsCreator.scala
@@ -34,7 +34,7 @@ trait AstForFunctionsCreator {
 
     method.astParentFullName = parentNode.fullName
     method.astParentType = parentNode.label
-    val functionBinding = NewBinding().name(methodName).signature(signature)
+    val functionBinding = NewBinding().name(methodName).methodFullName(methodFullName).signature(signature)
     Ast(functionBinding).withBindsEdge(parentNode, functionBinding).withRefEdge(functionBinding, method)
   }
 


Test patch:
diff --git a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/EnumTests.scala b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/EnumTests.scala
index f305e17879a3..1070c6f09f47 100644
--- a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/EnumTests.scala
+++ b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/EnumTests.scala
@@ -20,7 +20,7 @@ class EnumTests extends AnyWordSpec with Matchers with Inside with CompleteCpgFi
         |    green = 20,
         |    blue
         |};""".stripMargin) { cpg =>
-      inside(cpg.typeDecl.internal.l) { case List(color) =>
+      inside(cpg.typeDecl.nameNot("<global>").internal.l) { case List(color) =>
         color.name shouldBe "color"
         color.code shouldBe "enum color"
         inside(color.member.l) { case List(red, yellow, green, blue) =>
@@ -48,7 +48,7 @@ class EnumTests extends AnyWordSpec with Matchers with Inside with CompleteCpgFi
         |    green = 20,
         |    blue
         |} C;""".stripMargin) { cpg =>
-      inside(cpg.typeDecl.filter(x => !x.isExternal).l) { case List(color, c) =>
+      inside(cpg.typeDecl.nameNot("<global>").filter(x => !x.isExternal).l) { case List(color, c) =>
         color.name shouldBe "color"
         color.code shouldBe "enum color"
         color.aliasTypeFullName shouldBe None
@@ -77,7 +77,7 @@ class EnumTests extends AnyWordSpec with Matchers with Inside with CompleteCpgFi
         |     high='h',
         |     low='l', // C++11 allows the extra comma
         |}; """.stripMargin) { cpg =>
-      inside(cpg.typeDecl.internal.l) { case List(altitude) =>
+      inside(cpg.typeDecl.nameNot("<global>").internal.l) { case List(altitude) =>
         altitude.name shouldBe "altitude"
         altitude.code shouldBe "enum altitude"
         inside(altitude.member.l) { case List(high, low) =>
@@ -105,7 +105,7 @@ class EnumTests extends AnyWordSpec with Matchers with Inside with CompleteCpgFi
         |    b,
         |    c
         |};""".stripMargin) { cpg =>
-      inside(cpg.typeDecl.internal.l) { case List(smallenum) =>
+      inside(cpg.typeDecl.nameNot("<global>").internal.l) { case List(smallenum) =>
         smallenum.name shouldBe "smallenum"
         smallenum.code shouldBe "enum smallenum"
         inside(smallenum.member.l) { case List(a, b, c) =>
@@ -127,7 +127,7 @@ class EnumTests extends AnyWordSpec with Matchers with Inside with CompleteCpgFi
          |    e,
          |    f
          |};""".stripMargin) { cpg =>
-      inside(cpg.typeDecl.internal.l) { case List(anon) =>
+      inside(cpg.typeDecl.nameNot("<global>").internal.l) { case List(anon) =>
         anon.name shouldBe "anonymous_enum_0"
         anon.code shouldBe "enum"
         inside(anon.member.l) { case List(d, e, f) =>
@@ -147,7 +147,7 @@ class EnumTests extends AnyWordSpec with Matchers with Inside with CompleteCpgFi
        |};
        |int x = X::a;
        |""".stripMargin) { cpg =>
-      inside(cpg.typeDecl.internal.l) { case List(x) =>
+      inside(cpg.typeDecl.nameNot("<global>").internal.l) { case List(x) =>
         x.name shouldBe "X"
         x.code shouldBe "enum X"
         inside(x.member.l) { case List(a, b) =>
diff --git a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/TemplateTests.scala b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/TemplateTests.scala
index fa6bd7c750a2..e3361d0a4663 100644
--- a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/TemplateTests.scala
+++ b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/TemplateTests.scala
@@ -16,7 +16,7 @@ class TemplateTests extends AnyWordSpec with Matchers with Inside with CompleteC
         |using A = X<int>;
         |using B = Y<int, char>;
         |""".stripMargin) { cpg =>
-      inside(cpg.typeDecl.filter(x => !x.isExternal).l) { case List(x, y, a, b) =>
+      inside(cpg.typeDecl.nameNot("<global>").filter(x => !x.isExternal).l) { case List(x, y, a, b) =>
         x.name shouldBe "X"
         x.fullName shouldBe "X"
         x.aliasTypeFullName shouldBe Some("X<T>")
@@ -36,7 +36,7 @@ class TemplateTests extends AnyWordSpec with Matchers with Inside with CompleteC
         |template<typename T> class X;
         |template<typename A, typename B> class Y : public X<A> {};
         |""".stripMargin) { cpg =>
-      inside(cpg.typeDecl.filter(x => !x.isExternal).l) { case List(x, y) =>
+      inside(cpg.typeDecl.nameNot("<global>").filter(x => !x.isExternal).l) { case List(x, y) =>
         x.name shouldBe "X"
         x.fullName shouldBe "X"
         x.aliasTypeFullName shouldBe Some("X<T>")
@@ -50,7 +50,7 @@ class TemplateTests extends AnyWordSpec with Matchers with Inside with CompleteC
     "be correct for struct templates" in CompleteCpgFixture("""
         |template<typename A, typename B> struct Foo;
         |""".stripMargin) { cpg =>
-      inside(cpg.typeDecl.filter(x => !x.isExternal).l) { case List(foo) =>
+      inside(cpg.typeDecl.nameNot("<global>").filter(x => !x.isExternal).l) { case List(foo) =>
         foo.name shouldBe "Foo"
         foo.fullName shouldBe "Foo"
         foo.aliasTypeFullName shouldBe Some("Foo<A,B>")
diff --git a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/passes/AstCreationPassTests.scala b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/passes/AstCreationPassTests.scala
index 5ab1b10b420c..2b247884d0ee 100644
--- a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/passes/AstCreationPassTests.scala
+++ b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/passes/AstCreationPassTests.scala
@@ -163,14 +163,21 @@ class AstCreationPassTests
         l2.signature shouldBe "string anonymous_lambda_1 (string,string)"
       }
 
-      inside(cpg.typeDecl(lambda1FullName).head.bindsOut.l) { case List(binding: Binding) =>
-        binding.name shouldBe lambda1FullName
-        binding.signature shouldBe "int anonymous_lambda_0 (int,int)"
-        inside(binding.refOut.l) { case List(method: Method) =>
+      inside(cpg.typeDecl("<global>").head.bindsOut.l) { case List(bX: Binding, bY: Binding) =>
+        bX.name shouldBe lambda1FullName
+        bX.signature shouldBe "int anonymous_lambda_0 (int,int)"
+        inside(bX.refOut.l) { case List(method: Method) =>
           method.name shouldBe lambda1FullName
           method.fullName shouldBe lambda1FullName
           method.signature shouldBe "int anonymous_lambda_0 (int,int)"
         }
+        bY.name shouldBe lambda2FullName
+        bY.signature shouldBe "string anonymous_lambda_1 (string,string)"
+        inside(bY.refOut.l) { case List(method: Method) =>
+          method.name shouldBe lambda2FullName
+          method.fullName shouldBe lambda2FullName
+          method.signature shouldBe "string anonymous_lambda_1 (string,string)"
+        }
       }
     }
 
@@ -277,6 +284,7 @@ class AstCreationPassTests
       val lambda1Name = "anonymous_lambda_0"
       val signature1  = "int anonymous_lambda_0 (int)"
       val lambda2Name = "anonymous_lambda_1"
+      val signature2  = "int anonymous_lambda_1 (int)"
 
       cpg.local.name("x").order.l shouldBe List(1)
       cpg.local.name("foo1").order.l shouldBe List(3)
@@ -297,14 +305,21 @@ class AstCreationPassTests
         l1.signature shouldBe signature1
       }
 
-      inside(cpg.typeDecl(lambda1Name).head.bindsOut.l) { case List(binding: Binding) =>
-        binding.name shouldBe lambda1Name
-        binding.signature shouldBe signature1
-        inside(binding.refOut.l) { case List(method: Method) =>
+      inside(cpg.typeDecl("<global>").head.bindsOut.l) { case List(b1: Binding, b2: Binding) =>
+        b1.name shouldBe lambda1Name
+        b1.signature shouldBe signature1
+        inside(b1.refOut.l) { case List(method: Method) =>
           method.name shouldBe lambda1Name
           method.fullName shouldBe lambda1Name
           method.signature shouldBe signature1
         }
+        b2.name shouldBe lambda2Name
+        b2.signature shouldBe signature2
+        inside(b2.refOut.l) { case List(method: Method) =>
+          method.name shouldBe lambda2Name
+          method.fullName shouldBe lambda2Name
+          method.signature shouldBe signature2
+        }
       }
 
       inside(cpg.call("x").l) { case List(lambda1call) =>
@@ -1083,7 +1098,7 @@ class AstCreationPassTests
       val List(localMyFs) = cpg.local.name("my_fs").l
       localMyFs.order shouldBe 4
       localMyFs.referencingIdentifiers.name.l shouldBe List("my_fs")
-      cpg.typeDecl.fullName.l.distinct shouldBe List("my_open", "main", "filesystem")
+      cpg.typeDecl.nameNot("<global>").fullName.l.distinct shouldBe List("filesystem")
     }
 
     "be correct for typedef enum" in TestAstOnlyFixture("""
diff --git a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/querying/NodeTypeStartersTests.scala b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/querying/NodeTypeStartersTests.scala
index 562faf6eb1d8..281d0f29f023 100644
--- a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/querying/NodeTypeStartersTests.scala
+++ b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/querying/NodeTypeStartersTests.scala
@@ -56,7 +56,7 @@ class NodeTypeStartersTests extends CCodeToCpgSuite {
   }
 
   "should allow retrieving type declarations" in {
-    cpg.typeDecl.internal.name.toSetMutable shouldBe Set("foo", "main")
+    cpg.typeDecl.nameNot("<global>").internal.name.toSetMutable shouldBe Set("foo")
   }
 
   "should allow retrieving members" in {
diff --git a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/CMethodTests.scala b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/CMethodTests.scala
new file mode 100644
index 000000000000..bbc9c282730b
--- /dev/null
+++ b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/CMethodTests.scala
@@ -0,0 +1,88 @@
+package io.joern.c2cpg.standard
+
+import io.joern.c2cpg.testfixtures.CCodeToCpgSuite
+import io.shiftleft.codepropertygraph.generated.NodeTypes
+import io.shiftleft.semanticcpg.language._
+
+import java.io.File
+
+class CMethodTest1 extends CCodeToCpgSuite {
+
+  override val code: String =
+    """
+      |  int main(int argc, char **argv) {
+      | }""".stripMargin
+
+  "should contain exactly one method node with correct fields" in {
+    inside(cpg.method.name("main").l) { case List(x) =>
+      x.name shouldBe "main"
+      x.fullName shouldBe "main"
+      x.code shouldBe "int main (int argc,char **argv)"
+      x.signature shouldBe "int main (int,char**)"
+      x.isExternal shouldBe false
+      x.order shouldBe 1
+      x.filename should (
+        startWith(File.separator) or // Unix
+          startWith regex "[A-Z]:"   // Windows
+      )
+      x.lineNumber shouldBe Some(2)
+      x.lineNumberEnd shouldBe Some(3)
+      x.columnNumber shouldBe Some(2)
+      x.columnNumberEnd shouldBe Some(2)
+    }
+  }
+
+  "should return correct number of lines" in {
+    cpg.method.name("main").numberOfLines.l shouldBe List(2)
+  }
+
+  "should allow traversing to parameters" in {
+    cpg.method.name("main").parameter.name.toSetMutable shouldBe Set("argc", "argv")
+  }
+
+  "should allow traversing to methodReturn" in {
+    cpg.method.name("main").methodReturn.typeFullName.l shouldBe List("int")
+  }
+
+  "should allow traversing to file" in {
+    cpg.method.name("main").file.name.l should not be empty
+  }
+
+}
+
+class CMethodTest2 extends CCodeToCpgSuite {
+  override val code = "int foo(); int bar() { return woo(); }"
+
+  "should identify method as stub" in {
+    cpg.method.isStub.name.toSetMutable shouldBe Set("<global>", "foo", "woo")
+    cpg.method.isNotStub.name.l shouldBe List("bar")
+  }
+}
+
+class CMethodTest3 extends CCodeToCpgSuite {
+  override val code = "void doFoo() {}"
+
+  "should not generate a type decl for method definitions" in {
+    inside(cpg.method.name("doFoo").l) { case List(x) =>
+      x.name shouldBe "doFoo"
+      x.fullName shouldBe "doFoo"
+      x.astParentType shouldBe NodeTypes.TYPE_DECL
+      x.astParentFullName should endWith("<global>")
+    }
+    cpg.typeDecl.fullName.l should not contain "doFoo"
+  }
+}
+
+class CMethodTest4 extends CCodeToCpgSuite {
+  override val code = "void doFoo();"
+
+  "should not generate a type decl for method declarations" in {
+    inside(cpg.method.name("doFoo").l) { case List(x) =>
+      x.name shouldBe "doFoo"
+      x.fullName shouldBe "doFoo"
+      x.astParentType shouldBe NodeTypes.TYPE_DECL
+      x.astParentFullName should endWith("<global>")
+    }
+    cpg.typeDecl.fullName.l should not contain "doFoo"
+  }
+}
diff --git a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/FileTests.scala b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/FileTests.scala
index 65137fa966e6..b87a64064d6d 100644
--- a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/FileTests.scala
+++ b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/FileTests.scala
@@ -46,7 +46,7 @@ class FileTests extends CCodeToCpgSuite {
   }
 
   "should allow traversing from file to its type declarations via namespace block" in {
-    cpg.file.nameNot(FileTraversal.UNKNOWN).typeDecl.name.toSetMutable shouldBe Set("foo", "bar", "my_struct")
+    cpg.file.nameNot(FileTraversal.UNKNOWN).typeDecl.nameNot("<global>").name.toSetMutable shouldBe Set("my_struct")
   }
 
   "should allow traversing to namespaces" in {
diff --git a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/MethodTests.scala b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/MethodTests.scala
deleted file mode 100644
index a05ec4ae1b62..000000000000
--- a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/MethodTests.scala
+++ /dev/null
@@ -1,58 +0,0 @@
-package io.joern.c2cpg.standard
-
-import io.joern.c2cpg.testfixtures.CCodeToCpgSuite
-import io.shiftleft.semanticcpg.language._
-
-import java.io.File
-
-class MethodTests extends CCodeToCpgSuite {
-
-  override val code: String =
-    """
-      |  int main(int argc, char **argv) {
-      | }""".stripMargin
-
-  "should contain exactly one method node with correct fields" in {
-    val List(x) = cpg.method.name("main").l
-    x.name shouldBe "main"
-    x.fullName shouldBe "main"
-    x.code shouldBe "int main (int argc,char **argv)"
-    x.signature shouldBe "int main (int,char**)"
-    x.isExternal shouldBe false
-    x.order shouldBe 1
-    x.filename should (
-      startWith(File.separator) or // Unix
-        startWith regex "[A-Z]:"   // Windows
-    )
-    x.lineNumber shouldBe Some(2)
-    x.lineNumberEnd shouldBe Some(3)
-    x.columnNumber shouldBe Some(2)
-    x.columnNumberEnd shouldBe Some(2)
-  }
-
-  "should return correct number of lines" in {
-    cpg.method.name("main").numberOfLines.l shouldBe List(2)
-  }
-
-  "should allow traversing to parameters" in {
-    cpg.method.name("main").parameter.name.toSetMutable shouldBe Set("argc", "argv")
-  }
-
-  "should allow traversing to methodReturn" in {
-    cpg.method.name("main").methodReturn.typeFullName.l shouldBe List("int")
-  }
-
-  "should allow traversing to file" in {
-    cpg.method.name("main").file.name.l should not be empty
-  }
-
-}
-
-class CMethodTests2 extends CCodeToCpgSuite {
-  override val code = "int foo(); int bar() { return woo(); }"
-
-  "should identify method as stub" in {
-    cpg.method.isStub.name.toSetMutable shouldBe Set("<global>", "foo", "woo")
-    cpg.method.isNotStub.name.l shouldBe List("bar")
-  }
-}
diff --git a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/NamespaceBlockTests.scala b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/NamespaceBlockTests.scala
index 12d18bbb43ee..5898026d5a37 100644
--- a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/NamespaceBlockTests.scala
+++ b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/NamespaceBlockTests.scala
@@ -6,8 +6,7 @@ import io.shiftleft.semanticcpg.language.types.structure.{FileTraversal, Namespa
 
 class NamespaceBlockTests extends CCodeToCpgSuite {
 
-  // The fuzzyC parser currently just ignores namespaces. We place symbols
-  // that can't be associated in a file into the namespace "<global>", and
+  // We place symbols that can't be associated in a file into the namespace "<global>", and
   // those which can in `filename:<global>`
 
   override val code: String =
@@ -40,7 +39,9 @@ class NamespaceBlockTests extends CCodeToCpgSuite {
   }
 
   "should allow traversing from namespace block to type declaration" in {
-    cpg.namespaceBlock.filenameNot(FileTraversal.UNKNOWN).ast.isTypeDecl.name.l shouldBe List("my_struct", "foo")
+    cpg.namespaceBlock.filenameNot(FileTraversal.UNKNOWN).ast.isTypeDecl.nameNot("<global>").name.l shouldBe List(
+      "my_struct"
+    )
   }
 
   "should allow traversing from namespace block to namespace" in {
diff --git a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/TypeDeclTests.scala b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/TypeDeclTests.scala
index f2e535f90186..278b33bb4326 100644
--- a/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/TypeDeclTests.scala
+++ b/joern-cli/frontends/c2cpg/src/test/scala/io/joern/c2cpg/standard/TypeDeclTests.scala
@@ -61,7 +61,7 @@ class TypeDeclTests extends CCodeToCpgSuite(FileDefaults.CPP_EXT) {
   }
 
   "should find exactly 1 internal type" in {
-    cpg.typeDecl.internal.name.toSetMutable shouldBe Set("foo")
+    cpg.typeDecl.nameNot("<global>").internal.name.toSetMutable shouldBe Set("foo")
   }
 
   "should find five external types (`bar`, `char`, `int`, `void`, `ANY`)" in {