Merge pull request #44 from bnorm/lambdas
Do not transform lambda expression bodies
This commit is contained in:
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.ir.expressions.IrCall
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrConst
|
import org.jetbrains.kotlin.ir.expressions.IrConst
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrContainerExpression
|
import org.jetbrains.kotlin.ir.expressions.IrContainerExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
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.IrStatementOrigin
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrWhen
|
import org.jetbrains.kotlin.ir.expressions.IrWhen
|
||||||
import org.jetbrains.kotlin.ir.util.dumpKotlinLike
|
import org.jetbrains.kotlin.ir.util.dumpKotlinLike
|
||||||
@@ -84,6 +85,8 @@ fun buildTree(expression: IrExpression): Node? {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitExpression(expression: IrExpression, data: 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) }
|
val node = data as? ExpressionNode ?: ExpressionNode().also { data.addChild(it) }
|
||||||
node.add(expression)
|
node.add(expression)
|
||||||
expression.acceptChildren(this, node)
|
expression.acceptChildren(this, node)
|
||||||
|
|||||||
@@ -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")))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user