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

Issue:
Compiler with the plugin fails with an exception on anonymous object comparing
The code is:
```
assert(object {  }.toString() == "foo")
```
The exception:
~~~
The root cause java.lang.AssertionError was thrown at: org.jetbrains.kotlin.backend.jvm.lower.AnonymousObjectSuperConstructorLowering.visitBlock(AnonymousObjectSuperConstructorLowering.kt:70)
...
Caused by: java.lang.AssertionError: object literal does not end in a constructor call
	at org.jetbrains.kotlin.backend.jvm.lower.AnonymousObjectSuperConstructorLowering.visitBlock(AnonymousObjectSuperConstructorLowering.kt:70)
	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitBlock(IrElementTransformerVoid.kt:170)
	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitBlock(IrElementTransformerVoid.kt:24)
~~~

Pull request description:
Fixes #77

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 79a7512..1dd5d4b 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
@@ -76,13 +76,6 @@ fun buildTree(expression: IrExpression): Node? {
 
   val tree = RootNode()
   expression.accept(object : IrElementVisitor<Unit, Node> {
-    val INCREMENT_DECREMENT_OPERATORS = setOf(
-      IrStatementOrigin.PREFIX_INCR,
-      IrStatementOrigin.PREFIX_DECR,
-      IrStatementOrigin.POSTFIX_INCR,
-      IrStatementOrigin.POSTFIX_DECR
-    )
-
     override fun visitElement(element: IrElement, data: Node) {
       element.acceptChildren(this, data)
     }
@@ -96,13 +89,14 @@ fun buildTree(expression: IrExpression): Node? {
     }
 
     override fun visitContainerExpression(expression: IrContainerExpression, data: Node) {
-      if (expression.origin in INCREMENT_DECREMENT_OPERATORS) {
+      if (expression.origin is IrStatementOrigin.SAFE_CALL) {
+        // Null safe expressions can be correctly navigated
+        super.visitContainerExpression(expression, data)
+      } else {
+        // Everything else is considered unsafe and terminates the expression tree
         val node = data as? ExpressionNode ?: ExpressionNode().also { data.addChild(it) }
         node.add(expression)
-        return // Skip the internals of increment/decrement operations
       }
-
-      super.visitContainerExpression(expression, data)
     }
 
     override fun visitTypeOperator(expression: IrTypeOperatorCall, data: Node) {


Test patch:
diff --git a/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/ObjectLiteralTest.kt b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/ObjectLiteralTest.kt
new file mode 100644
index 0000000..c7d04fb
--- /dev/null
+++ b/kotlin-power-assert-plugin/src/test/kotlin/com/bnorm/power/ObjectLiteralTest.kt
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2023 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 kotlin.test.Test
+
+class ObjectLiteralTest {
+  @Test
+  fun `internals of object literal should not be separated`() {
+    assertMessage(
+      """
+      fun main() {
+        assert(object { override fun toString() = "ANONYMOUS" }.toString() == "toString()")
+      }""",
+      """
+      Assertion failed
+      assert(object { override fun toString() = "ANONYMOUS" }.toString() == "toString()")
+             |                                                |          |
+             |                                                |          false
+             |                                                ANONYMOUS
+             ANONYMOUS
+      """.trimIndent(),
+    )
+  }
+}