Repository: bnorm/kotlin-power-assert (kotlin)

Issue:
Compiler crash when trying to extend the plugin to kotlin.require and kotlin.check
Having power assertions on assert() is nice, but almost all the assertions in my codebase are `require` or `check`. So:

```
configure<com.bnorm.power.PowerAssertGradleExtension> {
    functions = listOf("kotlin.assert", "kotlin.test.assertTrue", "kotlin.require")
}
```

But, with Kotlin 1.5 this doesn't work, kotlinc crashes with the attached crash dump.

[dump.txt](https://github.com/bnorm/kotlin-power-assert/files/6459190/dump.txt)

Pull request description:
Fixes #43

Patch:
diff --git a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/ExpressionTree.kt b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/ExpressionTree.kt
index 11efe60..b871571 100644
--- a/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/ExpressionTree.kt
+++ b/kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/diagram/ExpressionTree.kt
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.ir.expressions.IrCall
 import org.jetbrains.kotlin.ir.expressions.IrConst
 import org.jetbrains.kotlin.ir.expressions.IrContainerExpression
 import org.jetbrains.kotlin.ir.expressions.IrExpression
+import org.jetbrains.kotlin.ir.expressions.IrFunctionExpression
 import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
 import org.jetbrains.kotlin.ir.expressions.IrWhen
 import org.jetbrains.kotlin.ir.util.dumpKotlinLike
@@ -84,6 +85,8 @@ fun buildTree(expression: IrExpression): Node? {
     }
 
     override fun visitExpression(expression: IrExpression, data: Node) {
+      if (expression is IrFunctionExpression) return // Do not transform lambda expressions, especially their body
+
       val node = data as? ExpressionNode ?: ExpressionNode().also { data.addChild(it) }
       node.add(expression)
       expression.acceptChildren(this, node)


Test patch:
diff --git a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/LamdaTest.kt b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/LamdaTest.kt
new file mode 100644
index 0000000..9e2dce2
--- /dev/null
+++ b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/LamdaTest.kt
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2021 Brian Norman
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.bnorm.power
+
+import org.jetbrains.kotlin.name.FqName
+import org.junit.Test
+
+class LamdaTest {
+  @Test
+  fun `list operations assert`() {
+    assertMessage(
+      """
+      fun main() {
+        val list = listOf("Jane", "John")
+        assert(list.map { "Doe, ${'$'}it" }.any { it == "Scott, Michael" })
+      }""",
+      """
+      Assertion failed
+      assert(list.map { "Doe, ${'$'}it" }.any { it == "Scott, Michael" })
+             |    |                  |
+             |    |                  false
+             |    [Doe, Jane, Doe, John]
+             [Jane, John]
+      """.trimIndent()
+    )
+  }
+
+  @Test
+  fun `list operations require`() {
+    assertMessage(
+      """
+      fun main() {
+        val list = listOf("Jane", "John")
+        require(
+            value = list
+                .map { "Doe, ${'$'}it" }
+                .any { it == "Scott, Michael" }
+        )
+      }""",
+      """
+      Assertion failed
+      require(
+          value = list
+                  |
+                  [Jane, John]
+              .map { "Doe, ${'$'}it" }
+               |
+               [Doe, Jane, Doe, John]
+              .any { it == "Scott, Michael" }
+               |
+               false
+      )
+      """.trimIndent(),
+      PowerAssertComponentRegistrar(setOf(FqName("kotlin.require")))
+    )
+  }
+}