diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/DFGPass.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/DFGPass.kt index 9f5428e2a0..a2e5083f0c 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/DFGPass.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/DFGPass.kt @@ -147,17 +147,16 @@ class DFGPass(ctx: TranslationContext) : ComponentPass(ctx) { * `comprehension.statement`. */ protected fun handleCollectionComprehension(comprehension: CollectionComprehension) { - if (comprehension.comprehensionExpressions.size > 1) { + if (comprehension.comprehensionExpressions.isNotEmpty()) { comprehension.comprehensionExpressions - .subList(0, comprehension.comprehensionExpressions.size - 2) + .subList(0, comprehension.comprehensionExpressions.size - 1) .forEachIndexed { i, expr -> expr.nextDFG += comprehension.comprehensionExpressions[i + 1] } - } - if (comprehension.comprehensionExpressions.isNotEmpty()) comprehension.statement?.let { comprehension.comprehensionExpressions.last().nextDFG += it } + } comprehension.statement?.let { comprehension.prevDFG += it } } diff --git a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/graph/edges/collections/UnwrappedEdgeListTest.kt b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/graph/edges/collections/UnwrappedEdgeListTest.kt index 2d318ae5a6..9723546e78 100644 --- a/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/graph/edges/collections/UnwrappedEdgeListTest.kt +++ b/cpg-core/src/test/kotlin/de/fraunhofer/aisec/cpg/graph/edges/collections/UnwrappedEdgeListTest.kt @@ -53,6 +53,9 @@ class UnwrappedEdgeListTest { assertEquals(1, node2.prevEOGEdges.size) assertEquals(1, node3.prevEOGEdges.size) assertEquals(1, node3.prevEOG.size) + + assertEquals(listOf(node2, node3), node1.nextEOG.subList(0, 2)) + assertEquals(listOf(node1), node3.prevEOG.subList(0, 1)) } }