diff --git a/cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonAST.kt b/cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonAST.kt index 8b043b65fc..7ae5187e22 100644 --- a/cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonAST.kt +++ b/cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonAST.kt @@ -477,7 +477,7 @@ interface PythonAST { * * ast.expr = class expr(AST) */ - abstract class ExprBase(pyObject: PyObject) : AST(pyObject) + abstract class ExprBase(pyObject: PyObject) : AST(pyObject), WithPythonLocation /** * ``` diff --git a/cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonLanguageFrontend.kt b/cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonLanguageFrontend.kt index d3f471531c..82ef94f732 100644 --- a/cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonLanguageFrontend.kt +++ b/cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonLanguageFrontend.kt @@ -104,7 +104,7 @@ class PythonLanguageFrontend(language: Language, ctx: Tr mutableLines[lastLineIdx].length + physicalLocation.region.startColumn - physicalLocation.region.endColumn mutableLines[lastLineIdx] = mutableLines[lastLineIdx].dropLast(toRemove) - return mutableLines.toString() + return mutableLines.joinToString(separator = "\n") // TODO } return null } diff --git a/cpg-language-python/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonFrontendTest.kt b/cpg-language-python/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonFrontendTest.kt index 199e3a86e6..da75e58137 100644 --- a/cpg-language-python/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonFrontendTest.kt +++ b/cpg-language-python/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonFrontendTest.kt @@ -214,17 +214,15 @@ class PythonFrontendTest : BaseTest() { val body = main.body as? CompoundStatement assertNotNull(body) - val sel = - (body.statements.first() as? DeclarationStatement)?.singleDeclaration - as? VariableDeclaration + val sel = (body.statements.first() as? AssignExpression)?.declarations?.first() assertNotNull(sel) assertLocalName("sel", sel) assertEquals(tu.primitiveType("bool"), sel.type) - val initializer = sel.initializer as? Literal<*> - assertNotNull(initializer) - assertEquals(tu.primitiveType("bool"), initializer.type) - assertEquals("True", initializer.code) + val firstAssignment = sel.firstAssignment as? Literal<*> + assertNotNull(firstAssignment) + assertEquals(tu.primitiveType("bool"), firstAssignment.type) + assertEquals("True", firstAssignment.code) val `if` = body.statements[1] as? IfStatement assertNotNull(`if`)