From 9af944669a78e510796b064d752ef48e3b8fbdaa Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Wed, 22 Mar 2023 14:57:59 +0100 Subject: [PATCH] FIR2IR: bind fake overrides for classes on the fly right after member processing #KT-57441 Fixed --- .../fir/backend/Fir2IrClassifierStorage.kt | 14 +- ...errideInAnonymousWithDelegation.fir.ir.txt | 129 ++++++++++++++++++ ...errideInAnonymousWithDelegation.fir.kt.txt | 53 +++++++ 3 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/ir/irText/firProblems/FakeOverrideInAnonymousWithDelegation.fir.ir.txt create mode 100644 compiler/testData/ir/irText/firProblems/FakeOverrideInAnonymousWithDelegation.fir.kt.txt diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt index cd9396283fd..b51244f9ef3 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt @@ -259,9 +259,19 @@ class Fir2IrClassifierStorage( processMembersOfClassesOnTheFlyImmediately = true for ((klass, irClass) in localClassesCreatedOnTheFly) { processMembersOfClassCreatedOnTheFly(klass, irClass) + // See the problem from KT-57441 +// class Wrapper { +// private val dummy = object: Bar {} +// private val bar = object: Bar by dummy {} +// } +// interface Bar { +// val foo: String +// get() = "" +// } + // When we are building bar.foo fake override, we should call dummy.foo, + // so we should have object : Bar.foo fake override to be built and bound. + converter.bindFakeOverridesInClass(irClass) } - // Note: it's better to bind everything AFTER members are built, in case local classes are dependent on each other - localClassesCreatedOnTheFly.values.forEach(converter::bindFakeOverridesInClass) localClassesCreatedOnTheFly.clear() } diff --git a/compiler/testData/ir/irText/firProblems/FakeOverrideInAnonymousWithDelegation.fir.ir.txt b/compiler/testData/ir/irText/firProblems/FakeOverrideInAnonymousWithDelegation.fir.ir.txt new file mode 100644 index 00000000000..de874f3197a --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/FakeOverrideInAnonymousWithDelegation.fir.ir.txt @@ -0,0 +1,129 @@ +FILE fqName: fileName:/FakeOverrideInAnonymousWithDelegation.kt + CLASS CLASS name:Wrapper modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Wrapper + CONSTRUCTOR visibility:public <> () returnType:.Wrapper [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Wrapper modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:dummy visibility:private modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:dummy type:.Wrapper.dummy. visibility:private [final] + EXPRESSION_BODY + BLOCK type=.Wrapper.dummy. origin=OBJECT_LITERAL + CLASS CLASS name: modality:FINAL visibility:local superTypes:[.Bar] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Wrapper.dummy. + CONSTRUCTOR visibility:public <> () returnType:.Wrapper.dummy. [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name: modality:FINAL visibility:local superTypes:[.Bar]' + PROPERTY FAKE_OVERRIDE name:foo visibility:public modality:OPEN [fake_override,val] + overridden: + public open foo: kotlin.String [val] + FUN FAKE_OVERRIDE name: visibility:public modality:OPEN <> ($this:.Bar) returnType:kotlin.String [fake_override] + correspondingProperty: PROPERTY FAKE_OVERRIDE name:foo visibility:public modality:OPEN [fake_override,val] + overridden: + public open fun (): kotlin.String declared in .Bar + $this: VALUE_PARAMETER name: type:.Bar + 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 [fake_override,operator] declared in .Bar + $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 [fake_override] declared in .Bar + $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 [fake_override] declared in .Bar + $this: VALUE_PARAMETER name: type:kotlin.Any + CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Wrapper.dummy.' type=.Wrapper.dummy. origin=OBJECT_LITERAL + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:private modality:FINAL <> ($this:.Wrapper) returnType:.Wrapper.dummy. + correspondingProperty: PROPERTY name:dummy visibility:private modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Wrapper + BLOCK_BODY + RETURN type=kotlin.Nothing from='private final fun (): .Wrapper.dummy. declared in .Wrapper' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:dummy type:.Wrapper.dummy. visibility:private [final]' type=.Wrapper.dummy. origin=null + receiver: GET_VAR ': .Wrapper declared in .Wrapper.' type=.Wrapper origin=null + PROPERTY name:bar visibility:private modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:bar type:.Wrapper.bar. visibility:private [final] + EXPRESSION_BODY + BLOCK type=.Wrapper.bar. origin=OBJECT_LITERAL + CLASS CLASS name: modality:FINAL visibility:local superTypes:[.Bar] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Wrapper.bar. + CONSTRUCTOR visibility:public <> () returnType:.Wrapper.bar. [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name: modality:FINAL visibility:local superTypes:[.Bar]' + PROPERTY DELEGATED_MEMBER name:foo visibility:public modality:OPEN [val] + overridden: + public open foo: kotlin.String [val] + FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.Wrapper.bar.) returnType:kotlin.String + correspondingProperty: PROPERTY DELEGATED_MEMBER name:foo visibility:public modality:OPEN [val] + overridden: + public open fun (): kotlin.String declared in .Bar + $this: VALUE_PARAMETER name: type:.Wrapper.bar. + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun (): kotlin.String declared in .Wrapper.bar.' + CALL 'public open fun (): kotlin.String [fake_override] declared in .Wrapper.dummy.' type=kotlin.String origin=null + $this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:.Wrapper.dummy. visibility:private [final]' type=.Wrapper.dummy. origin=null + receiver: GET_VAR ': .Wrapper.bar. declared in .Wrapper.bar..' type=.Wrapper.bar. origin=null + FIELD DELEGATE name:$$delegate_0 type:.Wrapper.dummy. visibility:private [final] + EXPRESSION_BODY + CALL 'private final fun (): .Wrapper.dummy. declared in .Wrapper' type=.Wrapper.dummy. origin=GET_PROPERTY + $this: GET_VAR ': .Wrapper declared in .Wrapper' type=.Wrapper 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 [fake_override,operator] declared in .Bar + $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 [fake_override] declared in .Bar + $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 [fake_override] declared in .Bar + $this: VALUE_PARAMETER name: type:kotlin.Any + CONSTRUCTOR_CALL 'public constructor () [primary] declared in .Wrapper.bar.' type=.Wrapper.bar. origin=OBJECT_LITERAL + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:private modality:FINAL <> ($this:.Wrapper) returnType:.Wrapper.bar. + correspondingProperty: PROPERTY name:bar visibility:private modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Wrapper + BLOCK_BODY + RETURN type=kotlin.Nothing from='private final fun (): .Wrapper.bar. declared in .Wrapper' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:bar type:.Wrapper.bar. visibility:private [final]' type=.Wrapper.bar. origin=null + receiver: GET_VAR ': .Wrapper declared in .Wrapper.' type=.Wrapper 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 [operator] 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 + CLASS INTERFACE name:Bar modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Bar + PROPERTY name:foo visibility:public modality:OPEN [val] + FUN name: visibility:public modality:OPEN <> ($this:.Bar) returnType:kotlin.String + correspondingProperty: PROPERTY name:foo visibility:public modality:OPEN [val] + $this: VALUE_PARAMETER name: type:.Bar + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun (): kotlin.String declared in .Bar' + CONST String type=kotlin.String value="" + 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 + $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 diff --git a/compiler/testData/ir/irText/firProblems/FakeOverrideInAnonymousWithDelegation.fir.kt.txt b/compiler/testData/ir/irText/firProblems/FakeOverrideInAnonymousWithDelegation.fir.kt.txt new file mode 100644 index 00000000000..bce043e7896 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/FakeOverrideInAnonymousWithDelegation.fir.kt.txt @@ -0,0 +1,53 @@ +class Wrapper { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + private val dummy: + field = { // BLOCK + local class : Bar { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + } + + () + } + private get + + private val bar: + field = { // BLOCK + local class : Bar { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override val foo: String + override get(): String { + return .#$$delegate_0.() + } + + private /* final field */ val $$delegate_0: = .() + + } + + () + } + private get + +} + +interface Bar { + val foo: String + get(): String { + return "" + } + +}