From 522eeae062d9ad4ed99269d0f1b7c6e6e7a9cf01 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 25 Feb 2020 12:12:48 +0300 Subject: [PATCH] FIR2IR: standardize expression with smart cast conversion To convert smart cast expression, now we just convert original expression in standard way and wrap it with TYPE_OP. Before this commit original expression was converted in different way, that led to errors e.g. for this expression casting. --- .../src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt | 2 +- compiler/testData/codegen/box/jvm8/kt33054.kt | 1 - compiler/testData/codegen/box/regressions/kt4281.kt | 1 - compiler/testData/codegen/box/smartCasts/falseSmartCast.kt | 1 - .../testData/codegen/box/smartCasts/implicitReceiver.kt | 1 - .../codegen/box/smartCasts/implicitReceiverInWhen.kt | 1 - .../testData/codegen/box/smartCasts/implicitToGrandSon.kt | 1 - compiler/testData/codegen/box/typeInfo/kt2811.kt | 1 - compiler/testData/codegen/box/typeInfo/smartCastThis.kt | 1 - .../ir/irText/declarations/localDelegatedProperties.fir.txt | 3 ++- .../expressions/sam/samConversionsWithSmartCasts.fir.txt | 3 ++- .../irText/types/smartCastOnReceiverOfGenericType.fir.txt | 6 ++++-- 12 files changed, 9 insertions(+), 13 deletions(-) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index 6127597fcbe..ce0f5cabdf4 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -936,7 +936,7 @@ class Fir2IrVisitor( override fun visitExpressionWithSmartcast(expressionWithSmartcast: FirExpressionWithSmartcast, data: Any?): IrElement { // Generate the expression with the original type and then cast it to the smart cast type. - val value = expressionWithSmartcast.toIrExpression(expressionWithSmartcast.originalType).applyReceivers(expressionWithSmartcast) + val value = expressionWithSmartcast.originalExpression.toIrExpression() val castType = expressionWithSmartcast.typeRef.toIrType(session, declarationStorage) if (value.type == castType) return value return IrTypeOperatorCallImpl( diff --git a/compiler/testData/codegen/box/jvm8/kt33054.kt b/compiler/testData/codegen/box/jvm8/kt33054.kt index a4a2f810756..c49ac5dc9c0 100644 --- a/compiler/testData/codegen/box/jvm8/kt33054.kt +++ b/compiler/testData/codegen/box/jvm8/kt33054.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // JVM_TARGET: 1.8 diff --git a/compiler/testData/codegen/box/regressions/kt4281.kt b/compiler/testData/codegen/box/regressions/kt4281.kt index 3b8ba12c9eb..a1e84ddff49 100644 --- a/compiler/testData/codegen/box/regressions/kt4281.kt +++ b/compiler/testData/codegen/box/regressions/kt4281.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR abstract class C { fun test(x: Int) { if (x == 0) return diff --git a/compiler/testData/codegen/box/smartCasts/falseSmartCast.kt b/compiler/testData/codegen/box/smartCasts/falseSmartCast.kt index 22caecfb378..d4bbbbfd9bb 100644 --- a/compiler/testData/codegen/box/smartCasts/falseSmartCast.kt +++ b/compiler/testData/codegen/box/smartCasts/falseSmartCast.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class SuperFoo { public fun bar(): String { diff --git a/compiler/testData/codegen/box/smartCasts/implicitReceiver.kt b/compiler/testData/codegen/box/smartCasts/implicitReceiver.kt index adae422f59d..4206c7ded62 100644 --- a/compiler/testData/codegen/box/smartCasts/implicitReceiver.kt +++ b/compiler/testData/codegen/box/smartCasts/implicitReceiver.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class A { class B : A() { diff --git a/compiler/testData/codegen/box/smartCasts/implicitReceiverInWhen.kt b/compiler/testData/codegen/box/smartCasts/implicitReceiverInWhen.kt index c34ad3945f6..091174d542b 100644 --- a/compiler/testData/codegen/box/smartCasts/implicitReceiverInWhen.kt +++ b/compiler/testData/codegen/box/smartCasts/implicitReceiverInWhen.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class A { fun f(): String = diff --git a/compiler/testData/codegen/box/smartCasts/implicitToGrandSon.kt b/compiler/testData/codegen/box/smartCasts/implicitToGrandSon.kt index 45cd09089a8..8970e5fa716 100644 --- a/compiler/testData/codegen/box/smartCasts/implicitToGrandSon.kt +++ b/compiler/testData/codegen/box/smartCasts/implicitToGrandSon.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class A { open fun foo() = "FAIL" diff --git a/compiler/testData/codegen/box/typeInfo/kt2811.kt b/compiler/testData/codegen/box/typeInfo/kt2811.kt index 685aea42946..293eb80b20b 100644 --- a/compiler/testData/codegen/box/typeInfo/kt2811.kt +++ b/compiler/testData/codegen/box/typeInfo/kt2811.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class Test1 { fun test1(): String { if (this is Test2) { diff --git a/compiler/testData/codegen/box/typeInfo/smartCastThis.kt b/compiler/testData/codegen/box/typeInfo/smartCastThis.kt index 27d582d0f03..6ed06c50328 100644 --- a/compiler/testData/codegen/box/typeInfo/smartCastThis.kt +++ b/compiler/testData/codegen/box/typeInfo/smartCastThis.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR package h open class A { diff --git a/compiler/testData/ir/irText/declarations/localDelegatedProperties.fir.txt b/compiler/testData/ir/irText/declarations/localDelegatedProperties.fir.txt index a6f6239286d..517bd7baad5 100644 --- a/compiler/testData/ir/irText/declarations/localDelegatedProperties.fir.txt +++ b/compiler/testData/ir/irText/declarations/localDelegatedProperties.fir.txt @@ -20,5 +20,6 @@ FILE fqName: fileName:/localDelegatedProperties.kt GET_VAR 'val tmp_0: kotlin.Int [val] declared in .test2' type=kotlin.Int origin=null SET_VAR 'var x: IrErrorType [var] declared in .test2' type=kotlin.Unit origin=null CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null - $this: GET_VAR 'var x: IrErrorType [var] declared in .test2' type=kotlin.Int origin=null + $this: TYPE_OP type=kotlin.Int origin=IMPLICIT_CAST typeOperand=kotlin.Int + GET_VAR 'var x: IrErrorType [var] declared in .test2' type=IrErrorType origin=null other: CONST Int type=kotlin.Int value=1 diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.txt b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.txt index fc87d8703c3..34f704c1b25 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.txt @@ -87,7 +87,8 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt TYPE_OP type=kotlin.Function0 origin=CAST typeOperand=kotlin.Function0 GET_VAR 'a: kotlin.Function1 declared in .test7' type=kotlin.Function1 origin=null ERROR_CALL 'Unresolved reference: #' type=IrErrorType - GET_VAR 'a: kotlin.Function1 declared in .test7' type=kotlin.Function0 origin=null + TYPE_OP type=kotlin.Function0 origin=IMPLICIT_CAST typeOperand=kotlin.Function0 + GET_VAR 'a: kotlin.Function1 declared in .test7' type=kotlin.Function1 origin=null FUN name:test8 visibility:public modality:FINAL <> (a:kotlin.Function0) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Function0 BLOCK_BODY diff --git a/compiler/testData/ir/irText/types/smartCastOnReceiverOfGenericType.fir.txt b/compiler/testData/ir/irText/types/smartCastOnReceiverOfGenericType.fir.txt index 2ccea2a257f..c7c8b9453bd 100644 --- a/compiler/testData/ir/irText/types/smartCastOnReceiverOfGenericType.fir.txt +++ b/compiler/testData/ir/irText/types/smartCastOnReceiverOfGenericType.fir.txt @@ -33,8 +33,10 @@ FILE fqName: fileName:/smartCastOnReceiverOfGenericType.kt TYPE_OP type=kotlin.String origin=CAST typeOperand=kotlin.String GET_VAR 'c: kotlin.Any declared in .testInnerClass' type=kotlin.Any origin=null ERROR_CALL 'Unresolved reference: #' type=IrErrorType - GET_VAR 'b: kotlin.Any declared in .testInnerClass' type=kotlin.Int origin=null - GET_VAR 'c: kotlin.Any declared in .testInnerClass' type=kotlin.String origin=null + TYPE_OP type=kotlin.Int origin=IMPLICIT_CAST typeOperand=kotlin.Int + GET_VAR 'b: kotlin.Any declared in .testInnerClass' type=kotlin.Any origin=null + TYPE_OP type=kotlin.String origin=IMPLICIT_CAST typeOperand=kotlin.String + GET_VAR 'c: kotlin.Any declared in .testInnerClass' type=kotlin.Any origin=null FUN name:testNonSubstitutedTypeParameter visibility:public modality:FINAL (a:kotlin.Any, b:kotlin.Any) returnType:kotlin.Unit TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] VALUE_PARAMETER name:a index:0 type:kotlin.Any