Allow constants expression as argument to assertion function

This commit is contained in:
Brian Norman
2020-09-25 12:21:04 -05:00
parent bfba77a2b5
commit 4c29d2dbc7
2 changed files with 18 additions and 3 deletions
@@ -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())
@@ -399,6 +399,20 @@ assert(a == 42)
0
""".trimIndent())
}
@Test
fun constantExpression() {
assertMessage(
"""
fun main() {
assert(true)
assert(false)
}""",
"""
Assertion failed
""".trimIndent()
)
}
}
fun assertMessage(