diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCallTransformer.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCallTransformer.kt index 9558934f06a..d24fdd01194 100644 --- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCallTransformer.kt +++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertCallTransformer.kt @@ -105,6 +105,10 @@ class PowerAssertCallTransformer( val assertionArgument = expression.getValueArgument(0)!! val messageArgument = if (function.valueParameters.size == 2) expression.getValueArgument(1) else null + // If the tree does not contain any children, the expression is not transformable + val tree = buildAssertTree(assertionArgument) + val root = tree.children.singleOrNull() ?: return super.visitCall(expression) + val symbol = currentScope!!.scope.scopeOwnerSymbol DeclarationIrBuilder(context, symbol).run { at(expression) @@ -129,9 +133,6 @@ class PowerAssertCallTransformer( } } - val tree = buildAssertTree(assertionArgument) - val root = tree.children.single() - // println(assertionArgument.dump()) // println(tree.dump()) diff --git a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/test.kt b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/test.kt index e088ad45dbc..86c8b0d0306 100644 --- a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/test.kt +++ b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/test.kt @@ -399,6 +399,20 @@ assert(a == 42) 0 """.trimIndent()) } + + @Test + fun constantExpression() { + assertMessage( + """ +fun main() { + assert(true) + assert(false) +}""", + """ +Assertion failed +""".trimIndent() + ) + } } fun assertMessage(