From 1ce6e0c915e6cc1bb72cd7f2aac8bad416e91452 Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Thu, 21 Nov 2024 14:48:30 +0100 Subject: [PATCH] Fixed Go tests --- .../src/main/kotlin/de/fraunhofer/aisec/cpg/ScopeManager.kt | 6 ++++++ .../aisec/cpg/frontends/golang/StatementHandler.kt | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) 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")