diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirBodyResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirBodyResolveTransformer.kt index 577d8f52cb3..dd3b39477a2 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirBodyResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirBodyResolveTransformer.kt @@ -740,6 +740,15 @@ open class FirBodyResolveTransformer( } } + override fun transformOperatorCall(operatorCall: FirOperatorCall, data: Any?): CompositeTransformResult { + if (operatorCall.operation in FirOperation.BOOLEANS) { + return (operatorCall.transformChildren(this, noExpectedType) as FirOperatorCall).also { + it.resultType = booleanType + }.compose() + } + return super.transformOperatorCall(operatorCall, data) + } + // ----------------------- Util functions ----------------------- private inline fun withLabelAndReceiverType(labelName: Name, owner: FirElement, type: ConeKotlinType, block: () -> T): T { diff --git a/compiler/testData/ir/irText/declarations/localVarInDoWhile.fir.txt b/compiler/testData/ir/irText/declarations/localVarInDoWhile.fir.txt index 75009f307f7..90469031e0b 100644 --- a/compiler/testData/ir/irText/declarations/localVarInDoWhile.fir.txt +++ b/compiler/testData/ir/irText/declarations/localVarInDoWhile.fir.txt @@ -8,4 +8,4 @@ FILE fqName: fileName:/localVarInDoWhile.kt condition: CALL 'public final fun not (): kotlin.Boolean declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ arg0: GET_VAR 'val x: kotlin.Int [val] declared in .foo' type=kotlin.Int origin=null - arg1: CONST Int type=kotlin.Unit value=42 + arg1: CONST Int type=kotlin.Int value=42 diff --git a/compiler/testData/ir/irText/expressions/floatingPointComparisons/floatingPointCompareTo.fir.txt b/compiler/testData/ir/irText/expressions/floatingPointComparisons/floatingPointCompareTo.fir.txt index 0d00616998d..481d9ee311d 100644 --- a/compiler/testData/ir/irText/expressions/floatingPointComparisons/floatingPointCompareTo.fir.txt +++ b/compiler/testData/ir/irText/expressions/floatingPointComparisons/floatingPointCompareTo.fir.txt @@ -19,7 +19,7 @@ FILE fqName: fileName:/floatingPointCompareTo.kt then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'y: kotlin.Any declared in .test2d' type=kotlin.Any origin=null - arg1: CONST Int type=kotlin.Boolean value=0 + arg1: CONST Int type=kotlin.Int value=0 BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CONST Boolean type=kotlin.Boolean value=false @@ -42,7 +42,7 @@ FILE fqName: fileName:/floatingPointCompareTo.kt then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'y: kotlin.Any declared in .test3d' type=kotlin.Any origin=null - arg1: CONST Int type=kotlin.Boolean value=0 + arg1: CONST Int type=kotlin.Int value=0 BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CONST Boolean type=kotlin.Boolean value=false @@ -66,7 +66,7 @@ FILE fqName: fileName:/floatingPointCompareTo.kt then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'y: kotlin.Any declared in .test2f' type=kotlin.Any origin=null - arg1: CONST Int type=kotlin.Boolean value=0 + arg1: CONST Int type=kotlin.Int value=0 BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CONST Boolean type=kotlin.Boolean value=false @@ -89,7 +89,7 @@ FILE fqName: fileName:/floatingPointCompareTo.kt then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'y: kotlin.Any declared in .test3f' type=kotlin.Any origin=null - arg1: CONST Int type=kotlin.Boolean value=0 + arg1: CONST Int type=kotlin.Int value=0 BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CONST Boolean type=kotlin.Boolean value=false @@ -112,7 +112,7 @@ FILE fqName: fileName:/floatingPointCompareTo.kt then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'y: kotlin.Any declared in .testFD' type=kotlin.Any origin=null - arg1: CONST Int type=kotlin.Boolean value=0 + arg1: CONST Int type=kotlin.Int value=0 BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CONST Boolean type=kotlin.Boolean value=false @@ -135,7 +135,7 @@ FILE fqName: fileName:/floatingPointCompareTo.kt then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'y: kotlin.Any declared in .testDF' type=kotlin.Any origin=null - arg1: CONST Int type=kotlin.Boolean value=0 + arg1: CONST Int type=kotlin.Int value=0 BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CONST Boolean type=kotlin.Boolean value=false @@ -158,7 +158,7 @@ FILE fqName: fileName:/floatingPointCompareTo.kt then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'x: kotlin.Any declared in .test2fr' type=kotlin.Any origin=null - arg1: CONST Int type=kotlin.Boolean value=0 + arg1: CONST Int type=kotlin.Int value=0 BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CONST Boolean type=kotlin.Boolean value=false @@ -174,7 +174,7 @@ FILE fqName: fileName:/floatingPointCompareTo.kt then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'x: kotlin.Any declared in .test3fr' type=kotlin.Any origin=null - arg1: CONST Int type=kotlin.Boolean value=0 + arg1: CONST Int type=kotlin.Int value=0 BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CONST Boolean type=kotlin.Boolean value=false diff --git a/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.fir.txt b/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.fir.txt index 2ac7ef4d0b3..c504e11c56d 100644 --- a/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.fir.txt +++ b/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.fir.txt @@ -71,7 +71,9 @@ FILE fqName: fileName:/forWithImplicitReceivers.kt $receiver: VALUE_PARAMETER name: type:.IntCell BLOCK_BODY RETURN type=kotlin.Nothing from='public open fun hasNext (): kotlin.Boolean declared in .IReceiver' - ERROR_CALL 'Comparison of arguments with different types: kotlin/Int, kotlin/Boolean' type=kotlin.Boolean + CALL 'public final fun greater (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=GT + arg0: CALL 'public final fun (): kotlin.Int declared in .IntCell' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=0 FUN name:next visibility:public modality:OPEN <> ($this:.IReceiver, $receiver:.IntCell) returnType:kotlin.Int $this: VALUE_PARAMETER name: type:.IReceiver $receiver: VALUE_PARAMETER name: type:.IntCell diff --git a/compiler/testData/ir/irText/expressions/when.fir.txt b/compiler/testData/ir/irText/expressions/when.fir.txt index d18d7b3fe89..d43176f7d4d 100644 --- a/compiler/testData/ir/irText/expressions/when.fir.txt +++ b/compiler/testData/ir/irText/expressions/when.fir.txt @@ -98,25 +98,25 @@ FILE fqName: fileName:/when.kt BRANCH if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: GET_VAR 'val tmp1_subject: kotlin.Int [val] declared in .testComma' type=kotlin.Int origin=null - arg1: CONST Int type=kotlin.Boolean value=1 + arg1: CONST Int type=kotlin.Int value=1 then: CONST Boolean type=kotlin.Boolean value=true BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: GET_VAR 'val tmp1_subject: kotlin.Int [val] declared in .testComma' type=kotlin.Int origin=null - arg1: CONST Int type=kotlin.Boolean value=2 + arg1: CONST Int type=kotlin.Int value=2 then: CONST Boolean type=kotlin.Boolean value=true BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: GET_VAR 'val tmp1_subject: kotlin.Int [val] declared in .testComma' type=kotlin.Int origin=null - arg1: CONST Int type=kotlin.Boolean value=3 + arg1: CONST Int type=kotlin.Int value=3 then: CONST Boolean type=kotlin.Boolean value=true BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: GET_VAR 'val tmp1_subject: kotlin.Int [val] declared in .testComma' type=kotlin.Int origin=null - arg1: CONST Int type=kotlin.Boolean value=4 + arg1: CONST Int type=kotlin.Int value=4 then: CONST String type=kotlin.String value="1234" BRANCH if: WHEN type=kotlin.Boolean origin=OROR @@ -125,32 +125,32 @@ FILE fqName: fileName:/when.kt BRANCH if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: GET_VAR 'val tmp1_subject: kotlin.Int [val] declared in .testComma' type=kotlin.Int origin=null - arg1: CONST Int type=kotlin.Boolean value=5 + arg1: CONST Int type=kotlin.Int value=5 then: CONST Boolean type=kotlin.Boolean value=true BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: GET_VAR 'val tmp1_subject: kotlin.Int [val] declared in .testComma' type=kotlin.Int origin=null - arg1: CONST Int type=kotlin.Boolean value=6 + arg1: CONST Int type=kotlin.Int value=6 then: CONST Boolean type=kotlin.Boolean value=true BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: GET_VAR 'val tmp1_subject: kotlin.Int [val] declared in .testComma' type=kotlin.Int origin=null - arg1: CONST Int type=kotlin.Boolean value=7 + arg1: CONST Int type=kotlin.Int value=7 then: CONST String type=kotlin.String value="567" BRANCH if: WHEN type=kotlin.Boolean origin=OROR BRANCH if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: GET_VAR 'val tmp1_subject: kotlin.Int [val] declared in .testComma' type=kotlin.Int origin=null - arg1: CONST Int type=kotlin.Boolean value=8 + arg1: CONST Int type=kotlin.Int value=8 then: CONST Boolean type=kotlin.Boolean value=true BRANCH if: CONST Boolean type=kotlin.Boolean value=true then: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ arg0: GET_VAR 'val tmp1_subject: kotlin.Int [val] declared in .testComma' type=kotlin.Int origin=null - arg1: CONST Int type=kotlin.Boolean value=9 + arg1: CONST Int type=kotlin.Int value=9 then: CONST String type=kotlin.String value="89" BRANCH if: CONST Boolean type=kotlin.Boolean value=true diff --git a/compiler/testData/ir/irText/expressions/whileDoWhile.fir.txt b/compiler/testData/ir/irText/expressions/whileDoWhile.fir.txt index a3434c9fac2..3beec847d10 100644 --- a/compiler/testData/ir/irText/expressions/whileDoWhile.fir.txt +++ b/compiler/testData/ir/irText/expressions/whileDoWhile.fir.txt @@ -4,10 +4,14 @@ FILE fqName: fileName:/whileDoWhile.kt VAR name:x type:kotlin.Int [var] CONST Int type=kotlin.Int value=0 WHILE label=null origin=WHILE_LOOP - condition: ERROR_CALL 'Comparison of arguments with different types: kotlin/Int, kotlin/Unit' type=kotlin.Boolean + condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT + arg0: GET_VAR 'var x: kotlin.Int [var] declared in .test' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=0 body: BLOCK type=kotlin.Unit origin=null WHILE label=null origin=WHILE_LOOP - condition: ERROR_CALL 'Comparison of arguments with different types: kotlin/Int, kotlin/Unit' type=kotlin.Boolean + condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT + arg0: GET_VAR 'var x: kotlin.Int [var] declared in .test' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=5 body: BLOCK type=kotlin.Int origin=null VAR name: type:kotlin.Int [val] GET_VAR 'var x: kotlin.Int [var] declared in .test' type=kotlin.Int origin=null @@ -16,7 +20,9 @@ FILE fqName: fileName:/whileDoWhile.kt $this: GET_VAR 'val : kotlin.Int [val] declared in .test' type=kotlin.Int origin=null GET_VAR 'val : kotlin.Int [val] declared in .test' type=kotlin.Int origin=null WHILE label=null origin=WHILE_LOOP - condition: ERROR_CALL 'Comparison of arguments with different types: kotlin/Int, kotlin/Unit' type=kotlin.Boolean + condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT + arg0: GET_VAR 'var x: kotlin.Int [var] declared in .test' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=10 body: BLOCK type=kotlin.Int origin=null VAR name: type:kotlin.Int [val] GET_VAR 'var x: kotlin.Int [var] declared in .test' type=kotlin.Int origin=null @@ -26,7 +32,9 @@ FILE fqName: fileName:/whileDoWhile.kt GET_VAR 'val : kotlin.Int [val] declared in .test' type=kotlin.Int origin=null DO_WHILE label=null origin=DO_WHILE_LOOP body: BLOCK type=kotlin.Unit origin=null - condition: ERROR_CALL 'Comparison of arguments with different types: kotlin/Int, kotlin/Unit' type=kotlin.Boolean + condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT + arg0: GET_VAR 'var x: kotlin.Int [var] declared in .test' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=0 DO_WHILE label=null origin=DO_WHILE_LOOP body: BLOCK type=kotlin.Int origin=null VAR name: type:kotlin.Int [val] @@ -35,7 +43,9 @@ FILE fqName: fileName:/whileDoWhile.kt CALL 'public final fun inc (): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=null $this: GET_VAR 'val : kotlin.Int [val] declared in .test' type=kotlin.Int origin=null GET_VAR 'val : kotlin.Int [val] declared in .test' type=kotlin.Int origin=null - condition: ERROR_CALL 'Comparison of arguments with different types: kotlin/Int, kotlin/Unit' type=kotlin.Boolean + condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT + arg0: GET_VAR 'var x: kotlin.Int [var] declared in .test' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=15 DO_WHILE label=null origin=DO_WHILE_LOOP body: BLOCK type=kotlin.Int origin=null VAR name: type:kotlin.Int [val] @@ -44,7 +54,9 @@ FILE fqName: fileName:/whileDoWhile.kt CALL 'public final fun inc (): kotlin.Int declared in kotlin.Int' type=kotlin.Int origin=null $this: GET_VAR 'val : kotlin.Int [val] declared in .test' type=kotlin.Int origin=null GET_VAR 'val : kotlin.Int [val] declared in .test' type=kotlin.Int origin=null - condition: ERROR_CALL 'Comparison of arguments with different types: kotlin/Int, kotlin/Unit' type=kotlin.Boolean + condition: CALL 'public final fun less (arg0: kotlin.Int, arg1: kotlin.Int): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=LT + arg0: GET_VAR 'var x: kotlin.Int [var] declared in .test' type=kotlin.Int origin=null + arg1: CONST Int type=kotlin.Int value=20 FUN name:testSmartcastInCondition visibility:public modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY VAR name:a type:kotlin.Any? [val]