KT-36963 Deparenthesize !! argument when generating expression
This commit is contained in:
+5
@@ -1072,6 +1072,11 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest {
|
||||
runTest("compiler/testData/ir/irText/expressions/kt36956.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt36963.kt")
|
||||
public void testKt36963() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/expressions/kt36963.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaInCAO.kt")
|
||||
public void testLambdaInCAO() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/expressions/lambdaInCAO.kt");
|
||||
|
||||
+13
-11
@@ -62,9 +62,8 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat
|
||||
|
||||
fun generatePrefixExpression(expression: KtPrefixExpression): IrExpression {
|
||||
val ktOperator = expression.operationReference.getReferencedNameElementType()
|
||||
val irOperator = getPrefixOperator(ktOperator)
|
||||
|
||||
return when (irOperator) {
|
||||
return when (val irOperator = getPrefixOperator(ktOperator)) {
|
||||
null -> throw AssertionError("Unexpected prefix operator: $ktOperator")
|
||||
|
||||
in INCREMENT_DECREMENT_OPERATORS ->
|
||||
@@ -78,9 +77,8 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat
|
||||
|
||||
fun generatePostfixExpression(expression: KtPostfixExpression): IrExpression {
|
||||
val ktOperator = expression.operationReference.getReferencedNameElementType()
|
||||
val irOperator = getPostfixOperator(ktOperator)
|
||||
|
||||
return when (irOperator) {
|
||||
return when (val irOperator = getPostfixOperator(ktOperator)) {
|
||||
null -> throw AssertionError("Unexpected postfix operator: $ktOperator")
|
||||
|
||||
in INCREMENT_DECREMENT_OPERATORS ->
|
||||
@@ -130,9 +128,7 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat
|
||||
return generateBinaryOperatorAsCall(expression, null)
|
||||
}
|
||||
|
||||
val irOperator = getInfixOperator(ktOperator)
|
||||
|
||||
return when (irOperator) {
|
||||
return when (val irOperator = getInfixOperator(ktOperator)) {
|
||||
null -> throw AssertionError("Unexpected infix operator: $ktOperator")
|
||||
IrStatementOrigin.EQ -> AssignmentGenerator(statementGenerator).generateAssignment(expression)
|
||||
in AUGMENTED_ASSIGNMENTS -> AssignmentGenerator(statementGenerator).generateAugmentedAssignment(expression, irOperator)
|
||||
@@ -319,7 +315,9 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat
|
||||
val comparisonInfo = getPrimitiveNumericComparisonInfo(expression)
|
||||
val comparisonType = comparisonInfo?.comparisonType
|
||||
|
||||
val eqeqSymbol = context.irBuiltIns.ieee754equalsFunByOperandType[kotlinTypeToIrType(comparisonType)?.classifierOrNull] ?: context.irBuiltIns.eqeqSymbol
|
||||
val eqeqSymbol =
|
||||
context.irBuiltIns.ieee754equalsFunByOperandType[kotlinTypeToIrType(comparisonType)?.classifierOrNull]
|
||||
?: context.irBuiltIns.eqeqSymbol
|
||||
|
||||
val irEquals = primitiveOp2(
|
||||
expression.startOffsetSkippingComments, expression.endOffset,
|
||||
@@ -357,7 +355,8 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat
|
||||
if (comparisonInfo != null) {
|
||||
val comparisonType = comparisonInfo.comparisonType
|
||||
val eqeqSymbol =
|
||||
context.irBuiltIns.ieee754equalsFunByOperandType[kotlinTypeToIrType(comparisonType)?.classifierOrNull] ?: context.irBuiltIns.eqeqSymbol
|
||||
context.irBuiltIns.ieee754equalsFunByOperandType[kotlinTypeToIrType(comparisonType)?.classifierOrNull] ?: context.irBuiltIns
|
||||
.eqeqSymbol
|
||||
primitiveOp2(
|
||||
startOffset, endOffset,
|
||||
eqeqSymbol,
|
||||
@@ -453,7 +452,10 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat
|
||||
val comparisonType = comparisonInfo.comparisonType
|
||||
primitiveOp2(
|
||||
startOffset, endOffset,
|
||||
getComparisonOperatorSymbol(origin, kotlinTypeToIrType(comparisonType) ?: error("$comparisonType expected to be primitive")),
|
||||
getComparisonOperatorSymbol(
|
||||
origin,
|
||||
kotlinTypeToIrType(comparisonType) ?: error("$comparisonType expected to be primitive")
|
||||
),
|
||||
context.irBuiltIns.booleanType,
|
||||
origin,
|
||||
ktLeft.generateAsPrimitiveNumericComparisonOperand(comparisonInfo.leftPrimitiveType, comparisonInfo.comparisonType),
|
||||
@@ -491,7 +493,7 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat
|
||||
}[primitiveNumericType.classifierOrFail]!!
|
||||
|
||||
private fun generateExclExclOperator(expression: KtPostfixExpression, origin: IrStatementOrigin): IrExpression {
|
||||
val ktArgument = expression.baseExpression!!
|
||||
val ktArgument = KtPsiUtil.deparenthesize(expression.baseExpression!!)!!
|
||||
val irArgument = ktArgument.genExpr()
|
||||
val ktOperator = expression.operationReference
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
FILE fqName:<root> fileName:/kt36963.kt
|
||||
FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
BLOCK_BODY
|
||||
FUN name:test visibility:public modality:FINAL <> () returnType:kotlin.reflect.KFunction0<kotlin.Unit>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test (): kotlin.reflect.KFunction0<kotlin.Unit> declared in <root>'
|
||||
CALL 'public final fun CHECK_NOT_NULL <T0> (arg0: T0 of kotlin.internal.ir.CHECK_NOT_NULL?): T0 of kotlin.internal.ir.CHECK_NOT_NULL declared in kotlin.internal.ir' type=kotlin.reflect.KFunction0<kotlin.Unit> origin=EXCLEXCL
|
||||
<T0>: kotlin.reflect.KFunction0<kotlin.Unit>
|
||||
arg0: FUNCTION_REFERENCE 'public final fun foo (): kotlin.Unit declared in <root>' type=kotlin.reflect.KFunction0<kotlin.Unit> origin=null reflectionTarget=<same>
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo() {}
|
||||
|
||||
fun test() = (::foo)!!
|
||||
@@ -0,0 +1,9 @@
|
||||
FILE fqName:<root> fileName:/kt36963.kt
|
||||
FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
BLOCK_BODY
|
||||
FUN name:test visibility:public modality:FINAL <> () returnType:IrErrorType
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test (): IrErrorType declared in <root>'
|
||||
CALL 'public final fun CHECK_NOT_NULL <T0> (arg0: T0 of kotlin.internal.ir.CHECK_NOT_NULL?): T0 of kotlin.internal.ir.CHECK_NOT_NULL declared in kotlin.internal.ir' type=kotlin.reflect.KFunction0<kotlin.Unit> origin=EXCLEXCL
|
||||
<T0>: kotlin.reflect.KFunction0<kotlin.Unit>
|
||||
arg0: FUNCTION_REFERENCE 'public final fun foo (): kotlin.Unit declared in <root>' type=kotlin.reflect.KFunction0<kotlin.Unit> origin=null reflectionTarget=<same>
|
||||
@@ -1071,6 +1071,11 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
|
||||
runTest("compiler/testData/ir/irText/expressions/kt36956.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt36963.kt")
|
||||
public void testKt36963() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/expressions/kt36963.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaInCAO.kt")
|
||||
public void testLambdaInCAO() throws Exception {
|
||||
runTest("compiler/testData/ir/irText/expressions/lambdaInCAO.kt");
|
||||
|
||||
Reference in New Issue
Block a user