From 1ddf889d8a593bbbeeaa99d49e138fc5efa49f7d Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Thu, 18 Aug 2016 20:06:45 +0300 Subject: [PATCH] Comparisons: - for primitive types and kotlin.String, use IrBinaryOperatorExpression - for others, use call to 'compareTo' --- .../IrOperatorExpressionGenerator.kt | 38 +++-- .../ir/irText/conventionComparisons.kt | 14 +- .../ir/irText/conventionComparisons.txt | 46 ++++-- .../ir/irText/primitiveComparisons.kt | 33 +++- .../ir/irText/primitiveComparisons.txt | 148 +++++++++++++++++- .../testData/ir/irText/stringComparisons.kt | 4 + .../testData/ir/irText/stringComparisons.txt | 29 ++++ .../kotlin/ir/IrTextTestCaseGenerated.java | 6 + 8 files changed, 280 insertions(+), 38 deletions(-) create mode 100644 compiler/testData/ir/irText/stringComparisons.kt create mode 100644 compiler/testData/ir/irText/stringComparisons.txt diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrOperatorExpressionGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrOperatorExpressionGenerator.kt index 2e1516ddad8..ec2d11a09bf 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrOperatorExpressionGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/IrOperatorExpressionGenerator.kt @@ -16,6 +16,8 @@ package org.jetbrains.kotlin.psi2ir.generators +import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor import org.jetbrains.kotlin.ir.expressions.* @@ -26,8 +28,8 @@ import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtPrefixExpression import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset -import org.jetbrains.kotlin.psi2ir.load import org.jetbrains.kotlin.psi2ir.generators.values.* +import org.jetbrains.kotlin.psi2ir.load import org.jetbrains.kotlin.psi2ir.toExpectedType import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall @@ -139,19 +141,35 @@ class IrOperatorExpressionGenerator(val irStatementGenerator: IrStatementGenerat } private fun generateComparisonOperator(expression: KtBinaryExpression, irOperator: IrBinaryOperator): IrExpression { - val relatedCall = getResolvedCall(expression)!! - val relatedDescriptor = relatedCall.resultingDescriptor + val compareToCall = getResolvedCall(expression)!! + val compareToDescriptor = compareToCall.resultingDescriptor val irCallGenerator = IrCallGenerator(irStatementGenerator) - val irArgument0 = irCallGenerator.generateReceiver(expression.left!!, relatedCall.dispatchReceiver, relatedDescriptor.dispatchReceiverParameter!!)!! - val valueParameter0 = relatedDescriptor.valueParameters[0] - val irArgument1 = irCallGenerator.generateValueArgument(relatedCall.valueArgumentsByIndex!![0], valueParameter0)!! - return IrBinaryOperatorExpressionImpl( - expression.startOffset, expression.endOffset, context.builtIns.booleanType, - irOperator, relatedDescriptor, irArgument0, irArgument1 - ) + + return if (shouldKeepComparisonAsBinaryOperation(compareToDescriptor)) { + val irArgument0 = irCallGenerator.generateReceiver(expression.left!!, compareToCall.dispatchReceiver, compareToDescriptor.dispatchReceiverParameter!!)!! + val valueParameter0 = compareToDescriptor.valueParameters[0] + val irArgument1 = irCallGenerator.generateValueArgument(compareToCall.valueArgumentsByIndex!![0], valueParameter0)!! + IrBinaryOperatorExpressionImpl( + expression.startOffset, expression.endOffset, context.builtIns.booleanType, + irOperator, compareToDescriptor, irArgument0, irArgument1 + ) + } + else { + val irCompareToCall = irCallGenerator.generateCall(expression, compareToCall, irOperator) + IrBinaryOperatorExpressionImpl( + expression.startOffset, expression.endOffset, context.builtIns.booleanType, + irOperator, null, irCompareToCall, + IrLiteralExpressionImpl.int(expression.startOffset, expression.endOffset, context.builtIns.intType, 0) + ) + } } + private fun shouldKeepComparisonAsBinaryOperation(compareToDescriptor: CallableDescriptor) = + compareToDescriptor.dispatchReceiverParameter?.type.let { + it != null && (KotlinBuiltIns.isPrimitiveType(it) || KotlinBuiltIns.isString(it)) + } + private fun generateBinaryOperatorWithConventionalCall(expression: KtBinaryExpression, irOperator: IrOperator?): IrExpression { val operatorCall = getResolvedCall(expression)!! return IrCallGenerator(irStatementGenerator).generateCall(expression, operatorCall, irOperator) diff --git a/compiler/testData/ir/irText/conventionComparisons.kt b/compiler/testData/ir/irText/conventionComparisons.kt index a499300f653..b2c6ee464b3 100644 --- a/compiler/testData/ir/irText/conventionComparisons.kt +++ b/compiler/testData/ir/irText/conventionComparisons.kt @@ -1,4 +1,10 @@ -fun test1(a: String, b: String) = a > b -fun test2(a: String, b: String) = a < b -fun test3(a: String, b: String) = a >= b -fun test4(a: String, b: String) = a <= b +interface IA + +interface IB { + operator fun IA.compareTo(other: IA): Int +} + +fun IB.test1(a1: IA, a2: IA) = a1 > a2 +fun IB.test2(a1: IA, a2: IA) = a1 >= a2 +fun IB.test3(a1: IA, a2: IA) = a1 < a2 +fun IB.test4(a1: IA, a2: IA) = a1 <= a2 \ No newline at end of file diff --git a/compiler/testData/ir/irText/conventionComparisons.txt b/compiler/testData/ir/irText/conventionComparisons.txt index 6c2c95d796b..2162065c9b3 100644 --- a/compiler/testData/ir/irText/conventionComparisons.txt +++ b/compiler/testData/ir/irText/conventionComparisons.txt @@ -1,29 +1,43 @@ IrFile /conventionComparisons.kt - IrFunction public fun test1(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean + DUMMY IA + DUMMY IB + IrFunction public fun IB.test1(/*0*/ a1: IA, /*1*/ a2: IA): kotlin.Boolean IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int - GET_VAR a type=kotlin.String operator=null - GET_VAR b type=kotlin.String operator=null - IrFunction public fun test2(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean + BINARY_OP operator=GT type=kotlin.Boolean related=null + CALL .compareTo type=kotlin.Int operator=GT + $this: $RECEIVER of: test1 type=IB + $receiver: GET_VAR a1 type=IA operator=null + other: GET_VAR a2 type=IA operator=null + LITERAL Int type=kotlin.Int value='0' + IrFunction public fun IB.test2(/*0*/ a1: IA, /*1*/ a2: IA): kotlin.Boolean IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int - GET_VAR a type=kotlin.String operator=null - GET_VAR b type=kotlin.String operator=null - IrFunction public fun test3(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean + BINARY_OP operator=GTEQ type=kotlin.Boolean related=null + CALL .compareTo type=kotlin.Int operator=GTEQ + $this: $RECEIVER of: test2 type=IB + $receiver: GET_VAR a1 type=IA operator=null + other: GET_VAR a2 type=IA operator=null + LITERAL Int type=kotlin.Int value='0' + IrFunction public fun IB.test3(/*0*/ a1: IA, /*1*/ a2: IA): kotlin.Boolean IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int - GET_VAR a type=kotlin.String operator=null - GET_VAR b type=kotlin.String operator=null - IrFunction public fun test4(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean + BINARY_OP operator=LT type=kotlin.Boolean related=null + CALL .compareTo type=kotlin.Int operator=LT + $this: $RECEIVER of: test3 type=IB + $receiver: GET_VAR a1 type=IA operator=null + other: GET_VAR a2 type=IA operator=null + LITERAL Int type=kotlin.Int value='0' + IrFunction public fun IB.test4(/*0*/ a1: IA, /*1*/ a2: IA): kotlin.Boolean IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= - BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int - GET_VAR a type=kotlin.String operator=null - GET_VAR b type=kotlin.String operator=null + BINARY_OP operator=LTEQ type=kotlin.Boolean related=null + CALL .compareTo type=kotlin.Int operator=LTEQ + $this: $RECEIVER of: test4 type=IB + $receiver: GET_VAR a1 type=IA operator=null + other: GET_VAR a2 type=IA operator=null + LITERAL Int type=kotlin.Int value='0' diff --git a/compiler/testData/ir/irText/primitiveComparisons.kt b/compiler/testData/ir/irText/primitiveComparisons.kt index 3e64a3c8091..3d208a2fc8d 100644 --- a/compiler/testData/ir/irText/primitiveComparisons.kt +++ b/compiler/testData/ir/irText/primitiveComparisons.kt @@ -1,4 +1,29 @@ -fun test1(a: Int, b: Int) = a > b -fun test2(a: Int, b: Int) = a < b -fun test3(a: Int, b: Int) = a >= b -fun test4(a: Int, b: Int) = a <= b +fun btest1(a: Byte, b: Byte) = a > b +fun btest2(a: Byte, b: Byte) = a < b +fun btest3(a: Byte, b: Byte) = a >= b +fun btest4(a: Byte, b: Byte) = a <= b + +fun stest1(a: Short, b: Short) = a > b +fun stest2(a: Short, b: Short) = a < b +fun stest3(a: Short, b: Short) = a >= b +fun stest4(a: Short, b: Short) = a <= b + +fun itest1(a: Int, b: Int) = a > b +fun itest2(a: Int, b: Int) = a < b +fun itest3(a: Int, b: Int) = a >= b +fun itest4(a: Int, b: Int) = a <= b + +fun ltest1(a: Long, b: Long) = a > b +fun ltest2(a: Long, b: Long) = a < b +fun ltest3(a: Long, b: Long) = a >= b +fun ltest4(a: Long, b: Long) = a <= b + +fun ftest1(a: Float, b: Float) = a > b +fun ftest2(a: Float, b: Float) = a < b +fun ftest3(a: Float, b: Float) = a >= b +fun ftest4(a: Float, b: Float) = a <= b + +fun dtest1(a: Double, b: Double) = a > b +fun dtest2(a: Double, b: Double) = a < b +fun dtest3(a: Double, b: Double) = a >= b +fun dtest4(a: Double, b: Double) = a <= b diff --git a/compiler/testData/ir/irText/primitiveComparisons.txt b/compiler/testData/ir/irText/primitiveComparisons.txt index 0221fc23488..e51a1d2b043 100644 --- a/compiler/testData/ir/irText/primitiveComparisons.txt +++ b/compiler/testData/ir/irText/primitiveComparisons.txt @@ -1,29 +1,169 @@ IrFile /primitiveComparisons.kt - IrFunction public fun test1(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean + IrFunction public fun btest1(/*0*/ a: kotlin.Byte, /*1*/ b: kotlin.Byte): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Byte): kotlin.Int + GET_VAR a type=kotlin.Byte operator=null + GET_VAR b type=kotlin.Byte operator=null + IrFunction public fun btest2(/*0*/ a: kotlin.Byte, /*1*/ b: kotlin.Byte): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Byte): kotlin.Int + GET_VAR a type=kotlin.Byte operator=null + GET_VAR b type=kotlin.Byte operator=null + IrFunction public fun btest3(/*0*/ a: kotlin.Byte, /*1*/ b: kotlin.Byte): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Byte): kotlin.Int + GET_VAR a type=kotlin.Byte operator=null + GET_VAR b type=kotlin.Byte operator=null + IrFunction public fun btest4(/*0*/ a: kotlin.Byte, /*1*/ b: kotlin.Byte): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Byte): kotlin.Int + GET_VAR a type=kotlin.Byte operator=null + GET_VAR b type=kotlin.Byte operator=null + IrFunction public fun stest1(/*0*/ a: kotlin.Short, /*1*/ b: kotlin.Short): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Short): kotlin.Int + GET_VAR a type=kotlin.Short operator=null + GET_VAR b type=kotlin.Short operator=null + IrFunction public fun stest2(/*0*/ a: kotlin.Short, /*1*/ b: kotlin.Short): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Short): kotlin.Int + GET_VAR a type=kotlin.Short operator=null + GET_VAR b type=kotlin.Short operator=null + IrFunction public fun stest3(/*0*/ a: kotlin.Short, /*1*/ b: kotlin.Short): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Short): kotlin.Int + GET_VAR a type=kotlin.Short operator=null + GET_VAR b type=kotlin.Short operator=null + IrFunction public fun stest4(/*0*/ a: kotlin.Short, /*1*/ b: kotlin.Short): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Short): kotlin.Int + GET_VAR a type=kotlin.Short operator=null + GET_VAR b type=kotlin.Short operator=null + IrFunction public fun itest1(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Int): kotlin.Int GET_VAR a type=kotlin.Int operator=null GET_VAR b type=kotlin.Int operator=null - IrFunction public fun test2(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean + IrFunction public fun itest2(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Int): kotlin.Int GET_VAR a type=kotlin.Int operator=null GET_VAR b type=kotlin.Int operator=null - IrFunction public fun test3(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean + IrFunction public fun itest3(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Int): kotlin.Int GET_VAR a type=kotlin.Int operator=null GET_VAR b type=kotlin.Int operator=null - IrFunction public fun test4(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean + IrFunction public fun itest4(/*0*/ a: kotlin.Int, /*1*/ b: kotlin.Int): kotlin.Boolean IrExpressionBody BLOCK type= hasResult=false operator=null RETURN type= BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Int): kotlin.Int GET_VAR a type=kotlin.Int operator=null GET_VAR b type=kotlin.Int operator=null + IrFunction public fun ltest1(/*0*/ a: kotlin.Long, /*1*/ b: kotlin.Long): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Long): kotlin.Int + GET_VAR a type=kotlin.Long operator=null + GET_VAR b type=kotlin.Long operator=null + IrFunction public fun ltest2(/*0*/ a: kotlin.Long, /*1*/ b: kotlin.Long): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Long): kotlin.Int + GET_VAR a type=kotlin.Long operator=null + GET_VAR b type=kotlin.Long operator=null + IrFunction public fun ltest3(/*0*/ a: kotlin.Long, /*1*/ b: kotlin.Long): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Long): kotlin.Int + GET_VAR a type=kotlin.Long operator=null + GET_VAR b type=kotlin.Long operator=null + IrFunction public fun ltest4(/*0*/ a: kotlin.Long, /*1*/ b: kotlin.Long): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Long): kotlin.Int + GET_VAR a type=kotlin.Long operator=null + GET_VAR b type=kotlin.Long operator=null + IrFunction public fun ftest1(/*0*/ a: kotlin.Float, /*1*/ b: kotlin.Float): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Float): kotlin.Int + GET_VAR a type=kotlin.Float operator=null + GET_VAR b type=kotlin.Float operator=null + IrFunction public fun ftest2(/*0*/ a: kotlin.Float, /*1*/ b: kotlin.Float): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Float): kotlin.Int + GET_VAR a type=kotlin.Float operator=null + GET_VAR b type=kotlin.Float operator=null + IrFunction public fun ftest3(/*0*/ a: kotlin.Float, /*1*/ b: kotlin.Float): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Float): kotlin.Int + GET_VAR a type=kotlin.Float operator=null + GET_VAR b type=kotlin.Float operator=null + IrFunction public fun ftest4(/*0*/ a: kotlin.Float, /*1*/ b: kotlin.Float): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Float): kotlin.Int + GET_VAR a type=kotlin.Float operator=null + GET_VAR b type=kotlin.Float operator=null + IrFunction public fun dtest1(/*0*/ a: kotlin.Double, /*1*/ b: kotlin.Double): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Double): kotlin.Int + GET_VAR a type=kotlin.Double operator=null + GET_VAR b type=kotlin.Double operator=null + IrFunction public fun dtest2(/*0*/ a: kotlin.Double, /*1*/ b: kotlin.Double): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Double): kotlin.Int + GET_VAR a type=kotlin.Double operator=null + GET_VAR b type=kotlin.Double operator=null + IrFunction public fun dtest3(/*0*/ a: kotlin.Double, /*1*/ b: kotlin.Double): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Double): kotlin.Int + GET_VAR a type=kotlin.Double operator=null + GET_VAR b type=kotlin.Double operator=null + IrFunction public fun dtest4(/*0*/ a: kotlin.Double, /*1*/ b: kotlin.Double): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.Double): kotlin.Int + GET_VAR a type=kotlin.Double operator=null + GET_VAR b type=kotlin.Double operator=null diff --git a/compiler/testData/ir/irText/stringComparisons.kt b/compiler/testData/ir/irText/stringComparisons.kt new file mode 100644 index 00000000000..a499300f653 --- /dev/null +++ b/compiler/testData/ir/irText/stringComparisons.kt @@ -0,0 +1,4 @@ +fun test1(a: String, b: String) = a > b +fun test2(a: String, b: String) = a < b +fun test3(a: String, b: String) = a >= b +fun test4(a: String, b: String) = a <= b diff --git a/compiler/testData/ir/irText/stringComparisons.txt b/compiler/testData/ir/irText/stringComparisons.txt new file mode 100644 index 00000000000..692d173fd69 --- /dev/null +++ b/compiler/testData/ir/irText/stringComparisons.txt @@ -0,0 +1,29 @@ +IrFile /stringComparisons.kt + IrFunction public fun test1(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=GT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int + GET_VAR a type=kotlin.String operator=null + GET_VAR b type=kotlin.String operator=null + IrFunction public fun test2(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=LT type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int + GET_VAR a type=kotlin.String operator=null + GET_VAR b type=kotlin.String operator=null + IrFunction public fun test3(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=GTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int + GET_VAR a type=kotlin.String operator=null + GET_VAR b type=kotlin.String operator=null + IrFunction public fun test4(/*0*/ a: kotlin.String, /*1*/ b: kotlin.String): kotlin.Boolean + IrExpressionBody + BLOCK type= hasResult=false operator=null + RETURN type= + BINARY_OP operator=LTEQ type=kotlin.Boolean related=public open override /*1*/ fun compareTo(/*0*/ other: kotlin.String): kotlin.Int + GET_VAR a type=kotlin.String operator=null + GET_VAR b type=kotlin.String operator=null diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 2b36e661de4..26bad8da276 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -191,6 +191,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { doTest(fileName); } + @TestMetadata("stringComparisons.kt") + public void testStringComparisons() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/stringComparisons.kt"); + doTest(fileName); + } + @TestMetadata("stringPlus.kt") public void testStringPlus() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/stringPlus.kt");