diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/ScopeManager.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/ScopeManager.kt index e1042185da..29eead8d3b 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/ScopeManager.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/ScopeManager.kt @@ -93,6 +93,12 @@ class ScopeManager : ScopeProvider { val currentFunction: FunctionDeclaration? get() = this.firstScopeIsInstanceOrNull()?.astNode as? FunctionDeclaration + /** The current block, according to the scope that is currently active. */ + val currentBlock: Block? + get() = + currentScope?.astNode as? Block + ?: currentScope?.astNode?.firstParentOrNull { it is Block } as? Block + /** * The current method in the active scope tree, this ensures that 'this' keywords are mapped * correctly if a method contains a lambda or other types of function declarations diff --git a/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/golang/StatementHandler.kt b/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/golang/StatementHandler.kt index f9952558b5..a735e5baec 100644 --- a/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/golang/StatementHandler.kt +++ b/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/golang/StatementHandler.kt @@ -142,7 +142,7 @@ class StatementHandler(frontend: GoLanguageFrontend) : } // We need to find the current block / scope and add the statements to it - val currentBlock = case.firstParentOrNull { it is Block } as? Block + val currentBlock = frontend.scopeManager.currentBlock if (currentBlock == null) { log.error("could not find block to add case clauses")