diff --git a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/GraphExamples.kt b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/GraphExamples.kt index 4ccb5af4f00..760b4731d68 100644 --- a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/GraphExamples.kt +++ b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/GraphExamples.kt @@ -339,6 +339,31 @@ class GraphExamples { } } + fun getInferenceNestedNamespace( + config: TranslationConfiguration = + TranslationConfiguration.builder() + .defaultPasses() + .registerLanguage(StructTestLanguage(".")) + .inferenceConfiguration( + InferenceConfiguration.builder().inferRecords(true).build() + ) + .build() + ) = + testFrontend(config).build { + translationResult { + translationUnit("Test.java") { + record("Test") { + function("foo") { + body { + declare { variable("node", t("java.lang.String")) } + returnStmt { isImplicit = true } + } + } + } + } + } + } + fun getVariables( config: TranslationConfiguration = TranslationConfiguration.builder() diff --git a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/enhancements/InferenceTest.kt b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/enhancements/InferenceTest.kt index 9454a0a1abd..f58e930fb84 100644 --- a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/enhancements/InferenceTest.kt +++ b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/enhancements/InferenceTest.kt @@ -95,4 +95,26 @@ class InferenceTest { assertNotNull(nextField) assertLocalName("T*", nextField.type) } + + @Test + fun testNestedNamespace() { + val result = GraphExamples.getInferenceNestedNamespace() + with(result) { + val java = result.namespaces["java"] + assertNotNull(java) + assertLocalName("java", java) + + val javaLang = result.namespaces["java.lang"] + assertNotNull(javaLang) + assertLocalName("lang", javaLang) + // should exist in the scope of "java" + assertEquals(java, javaLang.scope?.astNode) + + val javaLangString = result.records["java.lang.String"] + assertNotNull(javaLangString) + assertLocalName("String", javaLangString) + // should exist in the scope of "java.lang" + assertEquals(javaLang, javaLangString.scope?.astNode) + } + } }