From 4388b30f87ceb80a83f5ec5281c364f7c5909b7f Mon Sep 17 00:00:00 2001 From: Jinseong Jeon Date: Fri, 27 Mar 2020 00:06:56 -0700 Subject: [PATCH] [FIR] Fix anonymous object handling as 'this' receiver --- .../jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt | 3 +-- compiler/testData/codegen/box/classes/kt940.kt | 1 - compiler/testData/codegen/box/classes/selfcreate.kt | 1 - .../captureFunctionInProperty.kt | 1 - .../box/closures/captureOuterProperty/inProperty.kt | 1 - .../captureOuterProperty/inPropertyFromSuperClass.kt | 1 - .../codegen/box/enum/enumWithLambdaParameter.kt | 1 - compiler/testData/codegen/box/enum/kt1119.kt | 1 - compiler/testData/codegen/box/enum/kt18731_2.kt | 1 - compiler/testData/codegen/box/enum/kt2350.kt | 1 - .../codegen/box/enum/kt7257_anonObjectMethod.kt | 1 + compiler/testData/codegen/box/functions/kt1199.kt | 1 - .../objects/anonymousObjectPropertyInitialization.kt | 1 - .../codegen/box/properties/classFieldInsideNested.kt | 1 - .../codegen/box/properties/fieldInsideField.kt | 1 - .../enumEntryReferenceFromEnumEntryClass.fir.txt | 12 ++++++------ .../expressions/multipleThisReferences.fir.txt | 2 +- .../testData/ir/irText/singletons/enumEntry.fir.txt | 2 +- .../types/genericDelegatedDeepProperty.fir.txt | 4 ++-- 19 files changed, 12 insertions(+), 25 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 d37f87cd142..82195ed7067 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 @@ -24,7 +24,6 @@ import org.jetbrains.kotlin.fir.scopes.impl.FirIntegerOperator import org.jetbrains.kotlin.fir.symbols.StandardClassIds import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol -import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol import org.jetbrains.kotlin.fir.types.ConeClassLikeType import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor @@ -286,7 +285,7 @@ class Fir2IrVisitor( override fun visitThisReceiverExpression(thisReceiverExpression: FirThisReceiverExpression, data: Any?): IrElement { val calleeReference = thisReceiverExpression.calleeReference - if (calleeReference.labelName == null && calleeReference.boundSymbol is FirRegularClassSymbol) { + if (calleeReference.labelName == null && calleeReference.boundSymbol is FirClassSymbol) { // Object case val firObject = (calleeReference.boundSymbol?.fir as? FirClass)?.takeIf { it is FirAnonymousObject || it is FirRegularClass && it.classKind == ClassKind.OBJECT diff --git a/compiler/testData/codegen/box/classes/kt940.kt b/compiler/testData/codegen/box/classes/kt940.kt index ad636f6a02c..f9e99b3716a 100644 --- a/compiler/testData/codegen/box/classes/kt940.kt +++ b/compiler/testData/codegen/box/classes/kt940.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // WITH_RUNTIME fun box() : String { diff --git a/compiler/testData/codegen/box/classes/selfcreate.kt b/compiler/testData/codegen/box/classes/selfcreate.kt index 2c6f1571e17..95d67471511 100644 --- a/compiler/testData/codegen/box/classes/selfcreate.kt +++ b/compiler/testData/codegen/box/classes/selfcreate.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class B () {} open class A(val b : B) { diff --git a/compiler/testData/codegen/box/closures/captureOuterProperty/captureFunctionInProperty.kt b/compiler/testData/codegen/box/closures/captureOuterProperty/captureFunctionInProperty.kt index 618388e5c7e..e2c507f3b28 100644 --- a/compiler/testData/codegen/box/closures/captureOuterProperty/captureFunctionInProperty.kt +++ b/compiler/testData/codegen/box/closures/captureOuterProperty/captureFunctionInProperty.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR interface T { fun result(): String } diff --git a/compiler/testData/codegen/box/closures/captureOuterProperty/inProperty.kt b/compiler/testData/codegen/box/closures/captureOuterProperty/inProperty.kt index e9d560a4de6..8f1846f7cfb 100644 --- a/compiler/testData/codegen/box/closures/captureOuterProperty/inProperty.kt +++ b/compiler/testData/codegen/box/closures/captureOuterProperty/inProperty.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR interface T { fun result(): String } diff --git a/compiler/testData/codegen/box/closures/captureOuterProperty/inPropertyFromSuperClass.kt b/compiler/testData/codegen/box/closures/captureOuterProperty/inPropertyFromSuperClass.kt index 17407627a37..2f7ff86a10c 100644 --- a/compiler/testData/codegen/box/closures/captureOuterProperty/inPropertyFromSuperClass.kt +++ b/compiler/testData/codegen/box/closures/captureOuterProperty/inPropertyFromSuperClass.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR interface T { fun result(): String } diff --git a/compiler/testData/codegen/box/enum/enumWithLambdaParameter.kt b/compiler/testData/codegen/box/enum/enumWithLambdaParameter.kt index c0aac58675c..d41886a5370 100644 --- a/compiler/testData/codegen/box/enum/enumWithLambdaParameter.kt +++ b/compiler/testData/codegen/box/enum/enumWithLambdaParameter.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // KT-4423 Enum with function not compiled enum class Sign(val str: String, val func: (x: Int, y: Int) -> Int){ diff --git a/compiler/testData/codegen/box/enum/kt1119.kt b/compiler/testData/codegen/box/enum/kt1119.kt index 1ca0b15b6b4..6445197faee 100644 --- a/compiler/testData/codegen/box/enum/kt1119.kt +++ b/compiler/testData/codegen/box/enum/kt1119.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR enum class Direction() { NORTH { val someSpecialValue = "OK" diff --git a/compiler/testData/codegen/box/enum/kt18731_2.kt b/compiler/testData/codegen/box/enum/kt18731_2.kt index efaf9415cea..e986919f9e1 100644 --- a/compiler/testData/codegen/box/enum/kt18731_2.kt +++ b/compiler/testData/codegen/box/enum/kt18731_2.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR enum class Bar { ONE { diff --git a/compiler/testData/codegen/box/enum/kt2350.kt b/compiler/testData/codegen/box/enum/kt2350.kt index 27fbdb770f9..d4a363062b3 100644 --- a/compiler/testData/codegen/box/enum/kt2350.kt +++ b/compiler/testData/codegen/box/enum/kt2350.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR enum class A(val b: String) { E1("OK"){ override fun t() = b }; diff --git a/compiler/testData/codegen/box/enum/kt7257_anonObjectMethod.kt b/compiler/testData/codegen/box/enum/kt7257_anonObjectMethod.kt index 4f5e5ce5bda..1f3e05f80f2 100644 --- a/compiler/testData/codegen/box/enum/kt7257_anonObjectMethod.kt +++ b/compiler/testData/codegen/box/enum/kt7257_anonObjectMethod.kt @@ -1,3 +1,4 @@ +// IGNORE_BACKEND_FIR: JVM_IR enum class X { B { val value2 = "K" diff --git a/compiler/testData/codegen/box/functions/kt1199.kt b/compiler/testData/codegen/box/functions/kt1199.kt index bac836ed00b..6fcfedac539 100644 --- a/compiler/testData/codegen/box/functions/kt1199.kt +++ b/compiler/testData/codegen/box/functions/kt1199.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR interface MyIterator { operator fun hasNext() : Boolean operator fun next() : T diff --git a/compiler/testData/codegen/box/objects/anonymousObjectPropertyInitialization.kt b/compiler/testData/codegen/box/objects/anonymousObjectPropertyInitialization.kt index b037ebc493c..4765e8858ba 100644 --- a/compiler/testData/codegen/box/objects/anonymousObjectPropertyInitialization.kt +++ b/compiler/testData/codegen/box/objects/anonymousObjectPropertyInitialization.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR interface T { fun foo(): String } diff --git a/compiler/testData/codegen/box/properties/classFieldInsideNested.kt b/compiler/testData/codegen/box/properties/classFieldInsideNested.kt index 858bbbe4832..0ac00ddb630 100644 --- a/compiler/testData/codegen/box/properties/classFieldInsideNested.kt +++ b/compiler/testData/codegen/box/properties/classFieldInsideNested.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR abstract class Your { abstract val your: String diff --git a/compiler/testData/codegen/box/properties/fieldInsideField.kt b/compiler/testData/codegen/box/properties/fieldInsideField.kt index 7d8627c6cad..e86fe70da9e 100644 --- a/compiler/testData/codegen/box/properties/fieldInsideField.kt +++ b/compiler/testData/codegen/box/properties/fieldInsideField.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR abstract class Your { abstract val your: String diff --git a/compiler/testData/ir/irText/expressions/enumEntryReferenceFromEnumEntryClass.fir.txt b/compiler/testData/ir/irText/expressions/enumEntryReferenceFromEnumEntryClass.fir.txt index 305555c4c72..1e074fca740 100644 --- a/compiler/testData/ir/irText/expressions/enumEntryReferenceFromEnumEntryClass.fir.txt +++ b/compiler/testData/ir/irText/expressions/enumEntryReferenceFromEnumEntryClass.fir.txt @@ -41,10 +41,10 @@ FILE fqName: fileName:/enumEntryReferenceFromEnumEntryClass.kt $this: VALUE_PARAMETER name: type:.MyEnum.Z BLOCK_BODY CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .MyEnum.Z' type=kotlin.Unit origin=EQ - $this: GET_VAR ': .MyEnum.Z declared in .MyEnum.Z' type=.MyEnum.Z origin=null + $this: GET_VAR ': .MyEnum.Z declared in .MyEnum.Z.bar' type=.MyEnum.Z origin=null : CONST Int type=kotlin.Int value=1 CALL 'public final fun foo (): kotlin.Unit declared in .MyEnum.Z' type=kotlin.Unit origin=null - $this: GET_VAR ': .MyEnum.Z declared in .MyEnum.Z' type=.MyEnum.Z origin=null + $this: GET_VAR ': .MyEnum.Z declared in .MyEnum.Z.bar' type=.MyEnum.Z origin=null PROPERTY name:aLambda visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:aLambda type:kotlin.Function0 visibility:private [final] EXPRESSION_BODY @@ -76,18 +76,18 @@ FILE fqName: fileName:/enumEntryReferenceFromEnumEntryClass.kt ANONYMOUS_INITIALIZER isStatic=false BLOCK_BODY CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .MyEnum.Z' type=kotlin.Unit origin=EQ - $this: GET_VAR ': .MyEnum.Z declared in .MyEnum.Z' type=.MyEnum.Z origin=null + $this: GET_OBJECT 'CLASS ENUM_ENTRY name:Z modality:FINAL visibility:private superTypes:[.MyEnum]' type=.MyEnum.Z : CONST Int type=kotlin.Int value=1 CALL 'public final fun foo (): kotlin.Unit declared in .MyEnum.Z' type=kotlin.Unit origin=null - $this: GET_VAR ': .MyEnum.Z declared in .MyEnum.Z' type=.MyEnum.Z origin=null + $this: GET_OBJECT 'CLASS ENUM_ENTRY name:Z modality:FINAL visibility:private superTypes:[.MyEnum]' type=.MyEnum.Z FUN name:test visibility:public modality:FINAL <> ($this:.MyEnum.Z.anObject.) returnType:kotlin.Unit $this: VALUE_PARAMETER name: type:.MyEnum.Z.anObject. BLOCK_BODY CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .MyEnum.Z' type=kotlin.Unit origin=EQ - $this: GET_VAR ': .MyEnum.Z declared in .MyEnum.Z' type=.MyEnum.Z origin=null + $this: GET_OBJECT 'CLASS ENUM_ENTRY name:Z modality:FINAL visibility:private superTypes:[.MyEnum]' type=.MyEnum.Z : CONST Int type=kotlin.Int value=1 CALL 'public final fun foo (): kotlin.Unit declared in .MyEnum.Z' type=kotlin.Unit origin=null - $this: GET_VAR ': .MyEnum.Z declared in .MyEnum.Z' type=.MyEnum.Z origin=null + $this: GET_OBJECT 'CLASS ENUM_ENTRY name:Z modality:FINAL visibility:private superTypes:[.MyEnum]' type=.MyEnum.Z CONSTRUCTOR_CALL 'private constructor () [primary] declared in .MyEnum.Z.anObject.' type=.MyEnum.Z.anObject. origin=OBJECT_LITERAL FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.MyEnum.Z) returnType:.MyEnum.Z.anObject. correspondingProperty: PROPERTY name:anObject visibility:public modality:FINAL [val] diff --git a/compiler/testData/ir/irText/expressions/multipleThisReferences.fir.txt b/compiler/testData/ir/irText/expressions/multipleThisReferences.fir.txt index de0355b4fa0..f7eb6099fdb 100644 --- a/compiler/testData/ir/irText/expressions/multipleThisReferences.fir.txt +++ b/compiler/testData/ir/irText/expressions/multipleThisReferences.fir.txt @@ -86,7 +86,7 @@ FILE fqName: fileName:/multipleThisReferences.kt EXPRESSION_BODY CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS $this: CALL 'public final fun (): kotlin.Int declared in .Outer.Inner' type=kotlin.Int origin=GET_PROPERTY - $this: GET_VAR ': .Host.test. declared in .Host.test.' type=.Host.test. origin=null + $this: GET_VAR ': .Host declared in .Host.test' type=.Host origin=null other: CALL 'public final fun (): kotlin.Int declared in .Host' type=kotlin.Int origin=GET_PROPERTY $this: GET_VAR ': .Host declared in .Host.test' type=.Host origin=null FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Host.test.) returnType:kotlin.Int diff --git a/compiler/testData/ir/irText/singletons/enumEntry.fir.txt b/compiler/testData/ir/irText/singletons/enumEntry.fir.txt index 47f23272148..b3a07db41e6 100644 --- a/compiler/testData/ir/irText/singletons/enumEntry.fir.txt +++ b/compiler/testData/ir/irText/singletons/enumEntry.fir.txt @@ -29,7 +29,7 @@ FILE fqName: fileName:/enumEntry.kt $this: VALUE_PARAMETER name: type:.Z.ENTRY.A BLOCK_BODY CALL 'public final fun test (): kotlin.Unit declared in .Z.ENTRY' type=kotlin.Unit origin=null - $this: GET_VAR ': .Z.ENTRY declared in .Z.ENTRY' type=.Z.ENTRY origin=null + $this: GET_OBJECT 'CLASS ENUM_ENTRY name:ENTRY modality:FINAL visibility:private superTypes:[.Z]' type=.Z.ENTRY FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] overridden: public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any diff --git a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.txt b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.txt index d2b5cc04e26..15b285a7456 100644 --- a/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.txt +++ b/compiler/testData/ir/irText/types/genericDelegatedDeepProperty.fir.txt @@ -304,10 +304,10 @@ FILE fqName: fileName:/genericDelegatedDeepProperty.kt : T of . : T of . p1: CALL 'public final fun (): T of . declared in .additionalText$delegate.' type=T of . origin=GET_PROPERTY - $this: GET_VAR ': .additionalText$delegate. declared in .additionalText$delegate.' type=.additionalText$delegate. origin=null + $this: GET_VAR ': .additionalText$delegate. declared in .additionalText$delegate..getValue' type=.additionalText$delegate. origin=null $receiver: GET_VAR 't: .Value., .CR.>> declared in .additionalText$delegate..getValue' type=.Value., .CR.>> origin=null p2: CALL 'public final fun (): T of . declared in .additionalText$delegate.' type=T of . origin=GET_PROPERTY - $this: GET_VAR ': .additionalText$delegate. declared in .additionalText$delegate.' type=.additionalText$delegate. origin=null + $this: GET_VAR ': .additionalText$delegate. declared in .additionalText$delegate..getValue' type=.additionalText$delegate. origin=null $receiver: GET_VAR 't: .Value., .CR.>> declared in .additionalText$delegate..getValue' type=.Value., .CR.>> origin=null CONSTRUCTOR_CALL 'private constructor () [primary] declared in .additionalText$delegate.' type=.additionalText$delegate. origin=OBJECT_LITERAL FUN DELEGATED_PROPERTY_ACCESSOR name: visibility:public modality:FINAL ($receiver:.Value., .CR.>>) returnType:.P., T of .>