diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt index 96143f9d7fd..0af484968fe 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt @@ -301,7 +301,6 @@ class Fir2IrConverter( components.fakeOverrideGenerator = fakeOverrideGenerator val callGenerator = CallAndReferenceGenerator(components, fir2irVisitor, conversionScope) components.callGenerator = callGenerator - declarationStorage.annotationGenerator = AnnotationGenerator(components) for (firFile in firFiles) { converter.processClassHeaders(firFile) } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 8ff7a8d15c2..d7597de16ac 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -59,7 +59,7 @@ class Fir2IrDeclarationStorage( private val moduleDescriptor: FirModuleDescriptor ) : Fir2IrComponents by components { - internal var annotationGenerator: AnnotationGenerator? = null + private val annotationGenerator = AnnotationGenerator(this) private val firSymbolProvider = session.firSymbolProvider diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt index b6731e79305..9fa86e6c578 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt @@ -36,6 +36,8 @@ internal class DelegatedMemberGenerator( private val components: Fir2IrComponents ) : Fir2IrComponents by components { + private val annotationGenerator = AnnotationGenerator(this) + // Generate delegated members for [subClass]. The synthetic field [irField] has the super interface type. fun generate(irField: IrField, firField: FirField, firSubClass: FirClass<*>, subClass: IrClass) { val subClassLookupTag = firSubClass.symbol.toLookupTag() @@ -76,11 +78,12 @@ internal class DelegatedMemberGenerator( val member = declarationStorage.getIrPropertySymbol(unwrapped.symbol).owner as? IrProperty ?: return@processAllProperties - val irSubFunction = - generateDelegatedProperty(subClass, firSubClass, irField, member, propertySymbol.fir) + val irSubProperty = generateDelegatedProperty( + subClass, firSubClass, irField, member, propertySymbol.fir + ) - declarationStorage.cacheDelegatedProperty(propertySymbol.fir, irSubFunction) - subClass.addMember(irSubFunction) + declarationStorage.cacheDelegatedProperty(propertySymbol.fir, irSubProperty) + subClass.addMember(irSubProperty) } } @@ -135,6 +138,7 @@ internal class DelegatedMemberGenerator( delegateFunction.overriddenSymbols = delegateOverride.generateOverriddenFunctionSymbols(firSubClass, session, scopeSession, declarationStorage) .filter { it.owner != delegateFunction } + annotationGenerator.generate(delegateFunction, delegateOverride) val body = createDelegateBody(irField, delegateFunction, superFunction) delegateFunction.body = body @@ -197,16 +201,19 @@ internal class DelegatedMemberGenerator( firDelegateProperty, subClass, origin = IrDeclarationOrigin.DELEGATED_MEMBER, containingClass = firSubClass.symbol.toLookupTag() ) + annotationGenerator.generate(delegateProperty, firDelegateProperty) delegateProperty.getter!!.body = createDelegateBody(irField, delegateProperty.getter!!, superProperty.getter!!) delegateProperty.getter!!.overriddenSymbols = firDelegateProperty.generateOverriddenAccessorSymbols(firSubClass, isGetter = true, session, scopeSession, declarationStorage) + annotationGenerator.generate(delegateProperty.getter!!, firDelegateProperty) if (delegateProperty.isVar) { delegateProperty.setter!!.body = createDelegateBody(irField, delegateProperty.setter!!, superProperty.setter!!) delegateProperty.setter!!.overriddenSymbols = firDelegateProperty.generateOverriddenAccessorSymbols( firSubClass, isGetter = false, session, scopeSession, declarationStorage ) + annotationGenerator.generate(delegateProperty.setter!!, firDelegateProperty) } return delegateProperty diff --git a/compiler/testData/codegen/box/throws/delegationAndThrows_1_3.kt b/compiler/testData/codegen/box/throws/delegationAndThrows_1_3.kt index aca94e5bbc1..d14249a7759 100644 --- a/compiler/testData/codegen/box/throws/delegationAndThrows_1_3.kt +++ b/compiler/testData/codegen/box/throws/delegationAndThrows_1_3.kt @@ -1,6 +1,5 @@ // !LANGUAGE: -DoNotGenerateThrowsForDelegatedKotlinMembers // TARGET_BACKEND: JVM -// IGNORE_BACKEND_FIR: JVM_IR // WITH_RUNTIME // FILE: A.kt diff --git a/compiler/testData/compileKotlinAgainstKotlin/delegationAndAnnotations.kt b/compiler/testData/compileKotlinAgainstKotlin/delegationAndAnnotations.kt index b891ac615c5..0fe888bdeb5 100644 --- a/compiler/testData/compileKotlinAgainstKotlin/delegationAndAnnotations.kt +++ b/compiler/testData/compileKotlinAgainstKotlin/delegationAndAnnotations.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TARGET_BACKEND: JVM // WITH_RUNTIME // FILE: A.kt diff --git a/compiler/testData/ir/irText/classes/delegatedImplementationOfJavaInterface.fir.txt b/compiler/testData/ir/irText/classes/delegatedImplementationOfJavaInterface.fir.txt index d415e70da09..49e7a896708 100644 --- a/compiler/testData/ir/irText/classes/delegatedImplementationOfJavaInterface.fir.txt +++ b/compiler/testData/ir/irText/classes/delegatedImplementationOfJavaInterface.fir.txt @@ -51,6 +51,8 @@ FILE fqName: fileName:/delegatedImplementationOfJavaInterface.kt receiver: GET_VAR ': .Test declared in .Test.takeFlexible' type=.Test origin=null x: GET_VAR 'x: kotlin.String? declared in .Test.takeFlexible' type=kotlin.String? origin=null FUN DELEGATED_MEMBER name:returnNotNull visibility:public modality:OPEN <> ($this:.Test) returnType:@[EnhancedNullability] kotlin.String + annotations: + NotNull(value = ) overridden: public abstract fun returnNotNull (): @[EnhancedNullability] kotlin.String declared in .J $this: VALUE_PARAMETER name: type:.Test @@ -60,6 +62,8 @@ FILE fqName: fileName:/delegatedImplementationOfJavaInterface.kt $this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:.J visibility:local [final]' type=.J origin=null receiver: GET_VAR ': .Test declared in .Test.returnNotNull' type=.Test origin=null FUN DELEGATED_MEMBER name:returnNullable visibility:public modality:OPEN <> ($this:.Test) returnType:@[FlexibleNullability] kotlin.String? + annotations: + Nullable(value = ) overridden: public abstract fun returnNullable (): @[FlexibleNullability] kotlin.String? declared in .J $this: VALUE_PARAMETER name: type:.Test diff --git a/compiler/testData/ir/irText/declarations/annotations/annotationsOnDelegatedMembers.fir.txt b/compiler/testData/ir/irText/declarations/annotations/annotationsOnDelegatedMembers.fir.txt index 230b63660fb..6eae326f169 100644 --- a/compiler/testData/ir/irText/declarations/annotations/annotationsOnDelegatedMembers.fir.txt +++ b/compiler/testData/ir/irText/declarations/annotations/annotationsOnDelegatedMembers.fir.txt @@ -63,6 +63,8 @@ FILE fqName: fileName:/annotationsOnDelegatedMembers.kt receiver: GET_VAR ': .DFoo declared in .DFoo' type=.DFoo origin=null value: GET_VAR 'd: .IFoo declared in .DFoo.' type=.IFoo origin=null FUN DELEGATED_MEMBER name:testFun visibility:public modality:OPEN <> ($this:.DFoo) returnType:kotlin.Unit + annotations: + Ann overridden: public abstract fun testFun (): kotlin.Unit declared in .IFoo $this: VALUE_PARAMETER name: type:.DFoo @@ -71,6 +73,8 @@ FILE fqName: fileName:/annotationsOnDelegatedMembers.kt $this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:.IFoo visibility:local [final]' type=.IFoo origin=null receiver: GET_VAR ': .DFoo declared in .DFoo.testFun' type=.DFoo origin=null FUN DELEGATED_MEMBER name:testExtFun visibility:public modality:OPEN <> ($this:.DFoo, $receiver:kotlin.String) returnType:kotlin.Unit + annotations: + Ann overridden: public abstract fun testExtFun (): kotlin.Unit declared in .IFoo $this: VALUE_PARAMETER name: type:.DFoo @@ -81,6 +85,8 @@ FILE fqName: fileName:/annotationsOnDelegatedMembers.kt receiver: GET_VAR ': .DFoo declared in .DFoo.testExtFun' type=.DFoo origin=null $receiver: GET_VAR ': kotlin.String declared in .DFoo.testExtFun' type=kotlin.String origin=null PROPERTY DELEGATED_MEMBER name:testVal visibility:public modality:OPEN [val] + annotations: + Ann FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.DFoo) returnType:kotlin.String correspondingProperty: PROPERTY DELEGATED_MEMBER name:testVal visibility:public modality:OPEN [val] overridden: @@ -92,6 +98,8 @@ FILE fqName: fileName:/annotationsOnDelegatedMembers.kt $this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:.IFoo visibility:local [final]' type=.IFoo origin=null receiver: GET_VAR ': .DFoo declared in .DFoo.' type=.DFoo origin=null PROPERTY DELEGATED_MEMBER name:testExtVal visibility:public modality:OPEN [val] + annotations: + Ann FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.DFoo, $receiver:kotlin.String) returnType:kotlin.String correspondingProperty: PROPERTY DELEGATED_MEMBER name:testExtVal visibility:public modality:OPEN [val] overridden: diff --git a/compiler/testData/ir/irText/declarations/annotations/inheritingDeprecation.fir.txt b/compiler/testData/ir/irText/declarations/annotations/inheritingDeprecation.fir.txt index df51d7b9442..64901ed4215 100644 --- a/compiler/testData/ir/irText/declarations/annotations/inheritingDeprecation.fir.txt +++ b/compiler/testData/ir/irText/declarations/annotations/inheritingDeprecation.fir.txt @@ -44,6 +44,8 @@ FILE fqName: fileName:/inheritingDeprecation.kt receiver: GET_VAR ': .Delegated declared in .Delegated' type=.Delegated origin=null value: GET_VAR 'foo: .IFoo declared in .Delegated.' type=.IFoo origin=null PROPERTY DELEGATED_MEMBER name:prop visibility:public modality:OPEN [val] + annotations: + Deprecated(message = '', replaceWith = , level = ) FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.Delegated) returnType:kotlin.String correspondingProperty: PROPERTY DELEGATED_MEMBER name:prop visibility:public modality:OPEN [val] overridden: @@ -55,6 +57,8 @@ FILE fqName: fileName:/inheritingDeprecation.kt $this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:.IFoo visibility:local [final]' type=.IFoo origin=null receiver: GET_VAR ': .Delegated declared in .Delegated.' type=.Delegated origin=null PROPERTY DELEGATED_MEMBER name:extProp visibility:public modality:OPEN [val] + annotations: + Deprecated(message = '', replaceWith = , level = ) FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.Delegated, $receiver:kotlin.String) returnType:kotlin.String correspondingProperty: PROPERTY DELEGATED_MEMBER name:extProp visibility:public modality:OPEN [val] overridden: