From c605cb9855884a6c19b3355cd92b0c2646c49887 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Tue, 18 Jul 2023 16:07:46 +0200 Subject: [PATCH] [FIR2IR] Align object receiver generation with K1 #KT-59548 Fixed --- .../kotlin/fir/backend/Fir2IrVisitor.kt | 22 +- .../expressions/objectReference.fir.ir.txt | 191 ------------------ .../expressions/objectReference.fir.kt.txt | 92 --------- .../irText/expressions/objectReference.ir.txt | 20 ++ .../ir/irText/expressions/objectReference.kt | 14 +- .../irText/expressions/objectReference.kt.txt | 14 ++ .../expressions/objectReference.sig.kt.txt | 12 ++ 7 files changed, 68 insertions(+), 297 deletions(-) delete mode 100644 compiler/testData/ir/irText/expressions/objectReference.fir.ir.txt delete mode 100644 compiler/testData/ir/irText/expressions/objectReference.fir.kt.txt 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 e234df03f3b..f73cdfe0175 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 @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.KtPsiSourceElement import org.jetbrains.kotlin.KtSourceElement import org.jetbrains.kotlin.contracts.description.LogicOperationKind -import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.diagnostics.findChildByType @@ -48,7 +47,7 @@ import org.jetbrains.kotlin.ir.types.impl.IrErrorTypeImpl import org.jetbrains.kotlin.ir.util.constructors import org.jetbrains.kotlin.ir.util.defaultConstructor import org.jetbrains.kotlin.ir.util.defaultType -import org.jetbrains.kotlin.ir.util.parentClassOrNull +import org.jetbrains.kotlin.ir.util.isObject import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.SpecialNames @@ -595,15 +594,12 @@ class Fir2IrVisitor( ) } - // Note that this mimics psi2ir [StatementGenerator#isThisForClassPhysicallyAvailable]. - private fun isThisForClassPhysicallyAvailable(irClass: IrClass): Boolean { - var lastClass = conversionScope.lastClass() - while (lastClass != null) { - if (irClass == lastClass) return true - if (!lastClass.isInner) return false - lastClass = lastClass.parentClassOrNull - } - return false + // Note that this mimics psi2ir [StatementGenerator#shouldGenerateReceiverAsSingletonReference]. + private fun shouldGenerateReceiverAsSingletonReference(irClass: IrClass): Boolean { + val scopeOwner = conversionScope.parent() + return irClass.isObject && + scopeOwner != irClass && // For anonymous initializers + !((scopeOwner is IrFunction || scopeOwner is IrProperty || scopeOwner is IrField) && (scopeOwner as IrDeclaration).parent == irClass) // Members of object } override fun visitThisReceiverExpression( @@ -624,8 +620,8 @@ class Fir2IrVisitor( } else { classifierStorage.getIrClassSymbol(boundSymbol).owner } - // NB: IR generates anonymous objects as classes, not singleton objects - if (firClass is FirRegularClass && firClass.classKind == ClassKind.OBJECT && !isThisForClassPhysicallyAvailable(irClass)) { + + if (shouldGenerateReceiverAsSingletonReference(irClass)) { return thisReceiverExpression.convertWithOffsets { startOffset, endOffset -> IrGetObjectValueImpl(startOffset, endOffset, irClass.defaultType, irClass.symbol) } diff --git a/compiler/testData/ir/irText/expressions/objectReference.fir.ir.txt b/compiler/testData/ir/irText/expressions/objectReference.fir.ir.txt deleted file mode 100644 index 91907aae119..00000000000 --- a/compiler/testData/ir/irText/expressions/objectReference.fir.ir.txt +++ /dev/null @@ -1,191 +0,0 @@ -FILE fqName: fileName:/objectReference.kt - CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Z - CONSTRUCTOR visibility:private <> () returnType:.Z [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' - PROPERTY name:counter visibility:public modality:FINAL [var] - FIELD PROPERTY_BACKING_FIELD name:counter type:kotlin.Int visibility:private - EXPRESSION_BODY - CONST Int type=kotlin.Int value=0 - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Z) returnType:kotlin.Int - correspondingProperty: PROPERTY name:counter visibility:public modality:FINAL [var] - $this: VALUE_PARAMETER name: type:.Z - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in .Z' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:counter type:kotlin.Int visibility:private' type=kotlin.Int origin=null - receiver: GET_VAR ': .Z declared in .Z.' type=.Z origin=null - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Z, :kotlin.Int) returnType:kotlin.Unit - correspondingProperty: PROPERTY name:counter visibility:public modality:FINAL [var] - $this: VALUE_PARAMETER name: type:.Z - VALUE_PARAMETER name: index:0 type:kotlin.Int - BLOCK_BODY - SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:counter type:kotlin.Int visibility:private' type=kotlin.Unit origin=null - receiver: GET_VAR ': .Z declared in .Z.' type=.Z origin=null - value: GET_VAR ': kotlin.Int declared in .Z.' type=kotlin.Int origin=null - FUN name:foo visibility:public modality:FINAL <> ($this:.Z) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.Z - BLOCK_BODY - FUN name:bar visibility:public modality:FINAL <> ($this:.Z) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.Z - BLOCK_BODY - CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ - $this: GET_VAR ': .Z declared in .Z.bar' type=.Z origin=null - : CONST Int type=kotlin.Int value=1 - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_VAR ': .Z declared in .Z.bar' type=.Z origin=null - CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - : CONST Int type=kotlin.Int value=1 - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - CLASS CLASS name:Nested modality:FINAL visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Z.Nested - CONSTRUCTOR visibility:public <> () returnType:.Z.Nested [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Nested modality:FINAL visibility:public superTypes:[kotlin.Any]' - ANONYMOUS_INITIALIZER isStatic=false - BLOCK_BODY - CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - : CONST Int type=kotlin.Int value=1 - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - : CONST Int type=kotlin.Int value=1 - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - FUN name:test visibility:public modality:FINAL <> ($this:.Z.Nested) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.Z.Nested - BLOCK_BODY - CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - : CONST Int type=kotlin.Int value=1 - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - : CONST Int type=kotlin.Int value=1 - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - 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 declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - PROPERTY name:aLambda visibility:public modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:aLambda type:kotlin.Function0 visibility:private [final] - EXPRESSION_BODY - FUN_EXPR type=kotlin.Function0 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit - BLOCK_BODY - CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ - $this: GET_VAR ': .Z declared in .Z' type=.Z origin=null - : CONST Int type=kotlin.Int value=1 - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_VAR ': .Z declared in .Z' type=.Z origin=null - CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - : CONST Int type=kotlin.Int value=1 - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Z) returnType:kotlin.Function0 - correspondingProperty: PROPERTY name:aLambda visibility:public modality:FINAL [val] - $this: VALUE_PARAMETER name: type:.Z - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): kotlin.Function0 declared in .Z' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:aLambda type:kotlin.Function0 visibility:private [final]' type=kotlin.Function0 origin=null - receiver: GET_VAR ': .Z declared in .Z.' type=.Z origin=null - PROPERTY name:anObject visibility:public modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:anObject type:kotlin.Any visibility:private [final] - EXPRESSION_BODY - BLOCK type=.Z.anObject. origin=OBJECT_LITERAL - CLASS CLASS name: modality:FINAL visibility:local superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Z.anObject. - CONSTRUCTOR visibility:public <> () returnType:.Z.anObject. [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name: modality:FINAL visibility:local superTypes:[kotlin.Any]' - ANONYMOUS_INITIALIZER isStatic=false - BLOCK_BODY - CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - : CONST Int type=kotlin.Int value=1 - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - : CONST Int type=kotlin.Int value=1 - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - FUN name:test visibility:public modality:FINAL <> ($this:.Z.anObject.) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.Z.anObject. - BLOCK_BODY - CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - : CONST Int type=kotlin.Int value=1 - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - : CONST Int type=kotlin.Int value=1 - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - 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 declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - CONSTRUCTOR_CALL 'public constructor () declared in .Z.anObject.' type=.Z.anObject. origin=OBJECT_LITERAL - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Z) returnType:kotlin.Any - correspondingProperty: PROPERTY name:anObject visibility:public modality:FINAL [val] - $this: VALUE_PARAMETER name: type:.Z - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): kotlin.Any declared in .Z' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:anObject type:kotlin.Any visibility:private [final]' type=kotlin.Any origin=null - receiver: GET_VAR ': .Z declared in .Z.' type=.Z origin=null - 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 declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN name:test visibility:public modality:FINAL <> ($receiver:.Z) returnType:kotlin.Unit - $receiver: VALUE_PARAMETER name: type:.Z - BLOCK_BODY - CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ - $this: GET_VAR ': .Z declared in .test' type=.Z origin=null - : CONST Int type=kotlin.Int value=1 - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_VAR ': .Z declared in .test' type=.Z origin=null - CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z - : CONST Int type=kotlin.Int value=1 - CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null - $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z diff --git a/compiler/testData/ir/irText/expressions/objectReference.fir.kt.txt b/compiler/testData/ir/irText/expressions/objectReference.fir.kt.txt deleted file mode 100644 index a962e5b2fa8..00000000000 --- a/compiler/testData/ir/irText/expressions/objectReference.fir.kt.txt +++ /dev/null @@ -1,92 +0,0 @@ -object Z { - private constructor() /* primary */ { - super/*Any*/() - /* () */ - - } - - var counter: Int - field = 0 - get - set - - fun foo() { - } - - fun bar() { - .( = 1) - .foo() - Z.( = 1) - Z.foo() - } - - class Nested { - constructor() /* primary */ { - super/*Any*/() - /* () */ - - } - - init { - Z.( = 1) - Z.foo() - Z.( = 1) - Z.foo() - } - - fun test() { - Z.( = 1) - Z.foo() - Z.( = 1) - Z.foo() - } - - } - - val aLambda: Function0 - field = local fun () { - .( = 1) - .foo() - Z.( = 1) - Z.foo() - } - - get - - val anObject: Any - field = { // BLOCK - local class { - constructor() /* primary */ { - super/*Any*/() - /* () */ - - } - - init { - Z.( = 1) - Z.foo() - Z.( = 1) - Z.foo() - } - - fun test() { - Z.( = 1) - Z.foo() - Z.( = 1) - Z.foo() - } - - } - - () - } - get - -} - -fun Z.test() { - .( = 1) - .foo() - Z.( = 1) - Z.foo() -} diff --git a/compiler/testData/ir/irText/expressions/objectReference.ir.txt b/compiler/testData/ir/irText/expressions/objectReference.ir.txt index 9617ab78140..cb201ea7cb0 100644 --- a/compiler/testData/ir/irText/expressions/objectReference.ir.txt +++ b/compiler/testData/ir/irText/expressions/objectReference.ir.txt @@ -84,6 +84,23 @@ FILE fqName: fileName:/objectReference.kt overridden: public open fun toString (): kotlin.String declared in kotlin.Any $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:aFun visibility:public modality:FINAL <> ($this:.Z) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.Z + BLOCK_BODY + CALL 'public final fun withLambda (f: kotlin.Function0): kotlin.Unit declared in ' type=kotlin.Unit origin=null + f: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ + $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z + : CONST Int type=kotlin.Int value=1 + CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null + $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z + CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .Z' type=kotlin.Unit origin=EQ + $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z + : CONST Int type=kotlin.Int value=1 + CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null + $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z PROPERTY name:aLambda visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:aLambda type:kotlin.Function0 visibility:private [final] EXPRESSION_BODY @@ -189,3 +206,6 @@ FILE fqName: fileName:/objectReference.kt : CONST Int type=kotlin.Int value=1 CALL 'public final fun foo (): kotlin.Unit declared in .Z' type=kotlin.Unit origin=null $this: GET_OBJECT 'CLASS OBJECT name:Z modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.Z + FUN name:withLambda visibility:public modality:FINAL <> (f:kotlin.Function0) returnType:kotlin.Unit + VALUE_PARAMETER name:f index:0 type:kotlin.Function0 + BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/objectReference.kt b/compiler/testData/ir/irText/expressions/objectReference.kt index 43b651d8520..e831eab93b9 100644 --- a/compiler/testData/ir/irText/expressions/objectReference.kt +++ b/compiler/testData/ir/irText/expressions/objectReference.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL object Z { var counter = 0 fun foo() {} @@ -25,6 +26,15 @@ object Z { } } + fun aFun() { + withLambda { + counter = 1 + foo() + Z.counter = 1 + Z.foo() + } + } + val aLambda = { counter = 1 foo() @@ -54,4 +64,6 @@ fun Z.test() { foo() Z.counter = 1 Z.foo() -} \ No newline at end of file +} + +fun withLambda(f: () -> Unit) {} diff --git a/compiler/testData/ir/irText/expressions/objectReference.kt.txt b/compiler/testData/ir/irText/expressions/objectReference.kt.txt index bd825ea625b..34456abcd4a 100644 --- a/compiler/testData/ir/irText/expressions/objectReference.kt.txt +++ b/compiler/testData/ir/irText/expressions/objectReference.kt.txt @@ -43,6 +43,16 @@ object Z { } + fun aFun() { + withLambda(f = local fun () { + Z.( = 1) + Z.foo() + Z.( = 1) + Z.foo() + } +) + } + val aLambda: Function0 field = local fun () { Z.( = 1) @@ -90,3 +100,7 @@ fun Z.test() { Z.( = 1) Z.foo() } + +fun withLambda(f: Function0) { +} + diff --git a/compiler/testData/ir/irText/expressions/objectReference.sig.kt.txt b/compiler/testData/ir/irText/expressions/objectReference.sig.kt.txt index c9677ed1c39..55f1aa30080 100644 --- a/compiler/testData/ir/irText/expressions/objectReference.sig.kt.txt +++ b/compiler/testData/ir/irText/expressions/objectReference.sig.kt.txt @@ -76,6 +76,12 @@ object Z { // Public signature debug description: (){} private constructor() /* primary */ + // CHECK: + // Mangled name: Z#aFun(){} + // Public signature: /Z.aFun|-596272525427331003[0] + // Public signature debug description: aFun(){} + fun aFun(): Unit + // CHECK: // Mangled name: Z#bar(){} // Public signature: /Z.bar|496682602797471549[0] @@ -96,3 +102,9 @@ object Z { // Public signature debug description: test@Z(){} fun Z.test(): Unit +// CHECK: +// Mangled name: #withLambda(kotlin.Function0){} +// Public signature: /withLambda|-1561447572468305971[0] +// Public signature debug description: withLambda(kotlin.Function0){} +fun withLambda(f: Function0): Unit +