diff --git a/utils/spdx/src/main/kotlin/SpdxExpression.kt b/utils/spdx/src/main/kotlin/SpdxExpression.kt index bc7f4ec9e6354..45cc29e438a0f 100644 --- a/utils/spdx/src/main/kotlin/SpdxExpression.kt +++ b/utils/spdx/src/main/kotlin/SpdxExpression.kt @@ -300,6 +300,8 @@ class SpdxCompoundExpression( override fun validChoices(): Set = when (operator) { SpdxOperator.AND -> { + // If there is a top-level `AND` in an expression, create the combinations of all choices on the left + // and all choices on the right to get the overall valid choices. children.fold(setOf()) { acc, child -> if (acc.isEmpty()) { child.validChoices() @@ -317,7 +319,11 @@ class SpdxCompoundExpression( } } - SpdxOperator.OR -> children.flatMapTo(mutableSetOf()) { it.validChoices() } + SpdxOperator.OR -> { + // If there is a top-level `OR` in an expression, the operands already are the choices and just need to + // be checked themselves for choices. + children.flatMapTo(mutableSetOf()) { it.validChoices() } + } } override fun offersChoice(): Boolean =