From a11866ab5a56ea2dd52a3fdf9a823304047a2b96 Mon Sep 17 00:00:00 2001 From: "simon.ogorodnik" Date: Mon, 27 Apr 2020 23:00:47 +0300 Subject: [PATCH] [FIR2IR] Fix labeled this references --- .../kotlin/fir/backend/Fir2IrVisitor.kt | 42 +++++++++---------- .../kt6870_privatePropertyReference.kt | 1 - .../property/privateSetOuterClass.kt | 1 - .../testData/codegen/box/classes/kt5347.kt | 1 - .../tailRecursion/labeledThisReferences.kt | 1 - .../functionExpressionWithThisReference.kt | 1 - .../functionExpressionWithThisReferenceNI.kt | 1 - .../codegen/box/labels/propertyAccessor.kt | 1 - .../labels/propertyAccessorFunctionLiteral.kt | 1 - .../propertyAccessorInnerExtensionFun.kt | 1 - .../box/labels/propertyAccessorObject.kt | 1 - .../box/labels/propertyInClassAccessor.kt | 1 - .../box/localClasses/inExtensionProperty.kt | 1 - .../localClasses/inLocalExtensionFunction.kt | 1 - .../localClasses/inLocalExtensionProperty.kt | 1 - .../localClassCaptureExtensionReceiver.kt | 1 - .../codegen/box/objects/thisInConstructor.kt | 1 - 17 files changed, 20 insertions(+), 38 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 92561a475a6..3f21bc7d6cd 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 @@ -287,32 +287,30 @@ class Fir2IrVisitor( override fun visitThisReceiverExpression(thisReceiverExpression: FirThisReceiverExpression, data: Any?): IrElement { val calleeReference = thisReceiverExpression.calleeReference val boundSymbol = calleeReference.boundSymbol - if (calleeReference.labelName == null) { - if (boundSymbol is FirClassSymbol) { - // Object case - val firClass = boundSymbol.fir as FirClass - val irClass = classifierStorage.getCachedIrClass(firClass)!! - if (firClass is FirAnonymousObject || firClass is FirRegularClass && firClass.classKind == ClassKind.OBJECT) { - if (irClass != conversionScope.lastClass()) { - return thisReceiverExpression.convertWithOffsets { startOffset, endOffset -> - IrGetObjectValueImpl(startOffset, endOffset, irClass.defaultType, irClass.symbol) - } + if (boundSymbol is FirClassSymbol) { + // Object case + val firClass = boundSymbol.fir as FirClass + val irClass = classifierStorage.getCachedIrClass(firClass)!! + if (firClass is FirAnonymousObject || firClass is FirRegularClass && firClass.classKind == ClassKind.OBJECT) { + if (irClass != conversionScope.lastClass()) { + return thisReceiverExpression.convertWithOffsets { startOffset, endOffset -> + IrGetObjectValueImpl(startOffset, endOffset, irClass.defaultType, irClass.symbol) } } + } - val dispatchReceiver = conversionScope.dispatchReceiverParameter(irClass) - if (dispatchReceiver != null) { - return thisReceiverExpression.convertWithOffsets { startOffset, endOffset -> - IrGetValueImpl(startOffset, endOffset, dispatchReceiver.type, dispatchReceiver.symbol) - } + val dispatchReceiver = conversionScope.dispatchReceiverParameter(irClass) + if (dispatchReceiver != null) { + return thisReceiverExpression.convertWithOffsets { startOffset, endOffset -> + IrGetValueImpl(startOffset, endOffset, dispatchReceiver.type, dispatchReceiver.symbol) } - } else if (boundSymbol is FirCallableSymbol) { - val receiverSymbol = calleeReference.toSymbol(session, classifierStorage, declarationStorage, conversionScope) - val receiver = (receiverSymbol?.owner as? IrSimpleFunction)?.extensionReceiverParameter - if (receiver != null) { - return thisReceiverExpression.convertWithOffsets { startOffset, endOffset -> - IrGetValueImpl(startOffset, endOffset, receiver.type, receiver.symbol) - } + } + } else if (boundSymbol is FirCallableSymbol) { + val receiverSymbol = calleeReference.toSymbol(session, classifierStorage, declarationStorage, conversionScope) + val receiver = (receiverSymbol?.owner as? IrSimpleFunction)?.extensionReceiverParameter + if (receiver != null) { + return thisReceiverExpression.convertWithOffsets { startOffset, endOffset -> + IrGetValueImpl(startOffset, endOffset, receiver.type, receiver.symbol) } } } diff --git a/compiler/testData/codegen/box/callableReference/property/kt6870_privatePropertyReference.kt b/compiler/testData/codegen/box/callableReference/property/kt6870_privatePropertyReference.kt index 40b55add8c5..ab273e9919b 100644 --- a/compiler/testData/codegen/box/callableReference/property/kt6870_privatePropertyReference.kt +++ b/compiler/testData/codegen/box/callableReference/property/kt6870_privatePropertyReference.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JS_IR // TODO: muted automatically, investigate should it be ran for JS or not // IGNORE_BACKEND: JS, NATIVE diff --git a/compiler/testData/codegen/box/callableReference/property/privateSetOuterClass.kt b/compiler/testData/codegen/box/callableReference/property/privateSetOuterClass.kt index b6e14e22324..632b3d49dc5 100644 --- a/compiler/testData/codegen/box/callableReference/property/privateSetOuterClass.kt +++ b/compiler/testData/codegen/box/callableReference/property/privateSetOuterClass.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class A { var value: String = "fail1" private set diff --git a/compiler/testData/codegen/box/classes/kt5347.kt b/compiler/testData/codegen/box/classes/kt5347.kt index a1883790389..cca6a97b08e 100644 --- a/compiler/testData/codegen/box/classes/kt5347.kt +++ b/compiler/testData/codegen/box/classes/kt5347.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun test1(str: String): String { data class A(val x: Int) { fun foo() = str diff --git a/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/labeledThisReferences.kt b/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/labeledThisReferences.kt index ed6f89d0401..14b9cc0a6cb 100644 --- a/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/labeledThisReferences.kt +++ b/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/labeledThisReferences.kt @@ -1,5 +1,4 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JS_IR // TODO: muted automatically, investigate should it be ran for JS or not diff --git a/compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithThisReference.kt b/compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithThisReference.kt index eca7e8a8c2e..a9e1d43173e 100644 --- a/compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithThisReference.kt +++ b/compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithThisReference.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun Int.thisRef1() = fun () = this fun Int.thisRef2() = fun (): Int {return this} diff --git a/compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithThisReferenceNI.kt b/compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithThisReferenceNI.kt index b19250d3869..f44e247af37 100644 --- a/compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithThisReferenceNI.kt +++ b/compiler/testData/codegen/box/functions/functionExpression/functionExpressionWithThisReferenceNI.kt @@ -1,5 +1,4 @@ // !LANGUAGE: +NewInference -// IGNORE_BACKEND_FIR: JVM_IR // NewInference needed because of KT-26531 fun Int.thisRef1() = fun () = this diff --git a/compiler/testData/codegen/box/labels/propertyAccessor.kt b/compiler/testData/codegen/box/labels/propertyAccessor.kt index bd73e88dd72..b9973e82ddc 100644 --- a/compiler/testData/codegen/box/labels/propertyAccessor.kt +++ b/compiler/testData/codegen/box/labels/propertyAccessor.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR val Int.getter: Int get() { return this@getter diff --git a/compiler/testData/codegen/box/labels/propertyAccessorFunctionLiteral.kt b/compiler/testData/codegen/box/labels/propertyAccessorFunctionLiteral.kt index e9905463ca1..6d26e930ed2 100644 --- a/compiler/testData/codegen/box/labels/propertyAccessorFunctionLiteral.kt +++ b/compiler/testData/codegen/box/labels/propertyAccessorFunctionLiteral.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR val Int.getter: Int get() { return { diff --git a/compiler/testData/codegen/box/labels/propertyAccessorInnerExtensionFun.kt b/compiler/testData/codegen/box/labels/propertyAccessorInnerExtensionFun.kt index 65a993654d3..1a57fc6e039 100644 --- a/compiler/testData/codegen/box/labels/propertyAccessorInnerExtensionFun.kt +++ b/compiler/testData/codegen/box/labels/propertyAccessorInnerExtensionFun.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR val Int.getter: Int get() { val extFun: Int.() -> Int = { diff --git a/compiler/testData/codegen/box/labels/propertyAccessorObject.kt b/compiler/testData/codegen/box/labels/propertyAccessorObject.kt index f2833e414e5..1fc9f25aa82 100644 --- a/compiler/testData/codegen/box/labels/propertyAccessorObject.kt +++ b/compiler/testData/codegen/box/labels/propertyAccessorObject.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR interface Base { fun foo(): Int } diff --git a/compiler/testData/codegen/box/labels/propertyInClassAccessor.kt b/compiler/testData/codegen/box/labels/propertyInClassAccessor.kt index b7b86466dee..21cfd6428d9 100644 --- a/compiler/testData/codegen/box/labels/propertyInClassAccessor.kt +++ b/compiler/testData/codegen/box/labels/propertyInClassAccessor.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class Test { val Int.innerGetter: Int get() { diff --git a/compiler/testData/codegen/box/localClasses/inExtensionProperty.kt b/compiler/testData/codegen/box/localClasses/inExtensionProperty.kt index c6164af1222..6b0ed7cb97d 100644 --- a/compiler/testData/codegen/box/localClasses/inExtensionProperty.kt +++ b/compiler/testData/codegen/box/localClasses/inExtensionProperty.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR package test val A.a: String diff --git a/compiler/testData/codegen/box/localClasses/inLocalExtensionFunction.kt b/compiler/testData/codegen/box/localClasses/inLocalExtensionFunction.kt index 0a4b878100c..d7231d40d3d 100644 --- a/compiler/testData/codegen/box/localClasses/inLocalExtensionFunction.kt +++ b/compiler/testData/codegen/box/localClasses/inLocalExtensionFunction.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR package test class C(val s : String) { diff --git a/compiler/testData/codegen/box/localClasses/inLocalExtensionProperty.kt b/compiler/testData/codegen/box/localClasses/inLocalExtensionProperty.kt index 95d677cb927..6a628f41320 100644 --- a/compiler/testData/codegen/box/localClasses/inLocalExtensionProperty.kt +++ b/compiler/testData/codegen/box/localClasses/inLocalExtensionProperty.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR package test class C(val s : String) { diff --git a/compiler/testData/codegen/box/localClasses/localClassCaptureExtensionReceiver.kt b/compiler/testData/codegen/box/localClasses/localClassCaptureExtensionReceiver.kt index 23e35a4bf6e..b6708e33a90 100644 --- a/compiler/testData/codegen/box/localClasses/localClassCaptureExtensionReceiver.kt +++ b/compiler/testData/codegen/box/localClasses/localClassCaptureExtensionReceiver.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class Outer { val foo = "Foo" diff --git a/compiler/testData/codegen/box/objects/thisInConstructor.kt b/compiler/testData/codegen/box/objects/thisInConstructor.kt index 82469efd511..02f4ce346c9 100644 --- a/compiler/testData/codegen/box/objects/thisInConstructor.kt +++ b/compiler/testData/codegen/box/objects/thisInConstructor.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class A(open val v: String) { }