Skip to content

Commit 0fd6352

Browse files
committed
Using translation unit of source as start instead of global scope astNode
Currently, we use the global scope's `astNode` as a start node for inference of "global" things. However, this is very buggy, since the `astNode` of the global scope is assigned to the last TU we parse. If this TU was parsed in another language, we can run into situations where we infer things in the wrong language. This fixes that by using the source's TU as the inference start. This will then correctly use the sources langauge.
1 parent 4e9698b commit 0fd6352

File tree

1 file changed

+2
-2
lines changed
  • cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/inference

1 file changed

+2
-2
lines changed

cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/inference/PassHelper.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fun Pass<*>.tryNamespaceInference(name: Name, source: Node): NamespaceDeclaratio
8383
holder = tryScopeInference(parentName, source)
8484
}
8585

86-
return (holder ?: scopeManager.globalScope?.astNode)
86+
return (holder ?: source.translationUnit)
8787
?.startInference(ctx)
8888
?.inferNamespaceDeclaration(name, null, source)
8989
}
@@ -133,7 +133,7 @@ internal fun Pass<*>.tryRecordInference(type: Type, source: Node): RecordDeclara
133133
}
134134

135135
val record =
136-
(holder ?: scopeManager.globalScope?.astNode)
136+
(holder ?: source.translationUnit)
137137
?.startInference(ctx)
138138
?.inferRecordDeclaration(type, kind, source)
139139

0 commit comments

Comments
 (0)