From 948dc4f374599f5a816a44678d5bae24e73a52fd Mon Sep 17 00:00:00 2001 From: Pavel Kunyavskiy Date: Wed, 27 Oct 2021 15:21:18 +0300 Subject: [PATCH] Fix annotation class modality in stubs ^KT-49428 --- .../kotlin/ir/util/DeclarationStubGenerator.kt | 10 +++++++++- compiler/testData/ir/irText/regressions/kt45236.ir.txt | 2 +- .../irText/types/castsInsideCoroutineInference.ir.txt | 10 +++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt index e284d07275b..b078e7dc08d 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt @@ -244,6 +244,14 @@ abstract class DeclarationStubGenerator( } } + // in IR Generator enums also have special handling, but here we have not enough data for it + // probably, that is not a problem, because you can't add new enum value to external module + private fun getEffectiveModality(classDescriptor: ClassDescriptor): Modality = + if (DescriptorUtils.isAnnotationClass(classDescriptor)) + Modality.OPEN + else + classDescriptor.modality + fun generateClassStub(descriptor: ClassDescriptor): IrClass { val referenceClass = symbolTable.referenceClass(descriptor) if (referenceClass.isBound) { @@ -254,7 +262,7 @@ abstract class DeclarationStubGenerator( IrLazyClass( UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, it, descriptor, - descriptor.name, descriptor.kind, descriptor.visibility, descriptor.modality, + descriptor.name, descriptor.kind, descriptor.visibility, getEffectiveModality(descriptor), isCompanion = descriptor.isCompanionObject, isInner = descriptor.isInner, isData = descriptor.isData, diff --git a/compiler/testData/ir/irText/regressions/kt45236.ir.txt b/compiler/testData/ir/irText/regressions/kt45236.ir.txt index 5270c9c2792..85688c46fcf 100644 --- a/compiler/testData/ir/irText/regressions/kt45236.ir.txt +++ b/compiler/testData/ir/irText/regressions/kt45236.ir.txt @@ -181,7 +181,7 @@ FILE fqName: fileName:/kt45236.kt $this: VALUE_PARAMETER name: type:kotlin.Any FUN name:isError visibility:public modality:FINAL ($receiver:.NetRequestStatus.isError>) returnType:kotlin.Boolean annotations: - OptIn(markerClass = [CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB ANNOTATION_CLASS name:ExperimentalContracts modality:FINAL visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass]) + OptIn(markerClass = [CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB ANNOTATION_CLASS name:ExperimentalContracts modality:OPEN visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass]) TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any] $receiver: VALUE_PARAMETER name: type:.NetRequestStatus.isError> BLOCK_BODY diff --git a/compiler/testData/ir/irText/types/castsInsideCoroutineInference.ir.txt b/compiler/testData/ir/irText/types/castsInsideCoroutineInference.ir.txt index c8a313efda2..5183bbf7c12 100644 --- a/compiler/testData/ir/irText/types/castsInsideCoroutineInference.ir.txt +++ b/compiler/testData/ir/irText/types/castsInsideCoroutineInference.ir.txt @@ -1,7 +1,7 @@ FILE fqName: fileName:/castsInsideCoroutineInference.kt FUN name:scopedFlow visibility:public modality:FINAL (block:@[ExtensionFunctionType] kotlin.coroutines.SuspendFunction2<.CoroutineScope, .FlowCollector.scopedFlow>, kotlin.Unit>) returnType:.Flow.scopedFlow> annotations: - OptIn(markerClass = [CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB ANNOTATION_CLASS name:ExperimentalTypeInference modality:FINAL visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass]) + OptIn(markerClass = [CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB ANNOTATION_CLASS name:ExperimentalTypeInference modality:OPEN visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass]) TYPE_PARAMETER name:R index:0 variance: superTypes:[kotlin.Any?] VALUE_PARAMETER name:block index:0 type:@[ExtensionFunctionType] kotlin.coroutines.SuspendFunction2<.CoroutineScope, .FlowCollector.scopedFlow>, kotlin.Unit> annotations: @@ -53,7 +53,7 @@ FILE fqName: fileName:/castsInsideCoroutineInference.kt BLOCK_BODY FUN name:unsafeFlow visibility:public modality:FINAL (block:@[ExtensionFunctionType] kotlin.coroutines.SuspendFunction1<.FlowCollector.unsafeFlow>, kotlin.Unit>) returnType:.Flow.unsafeFlow> [inline] annotations: - OptIn(markerClass = [CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB ANNOTATION_CLASS name:ExperimentalTypeInference modality:FINAL visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass]) + OptIn(markerClass = [CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB ANNOTATION_CLASS name:ExperimentalTypeInference modality:OPEN visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass]) TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] VALUE_PARAMETER name:block index:0 type:@[ExtensionFunctionType] kotlin.coroutines.SuspendFunction1<.FlowCollector.unsafeFlow>, kotlin.Unit> [crossinline] annotations: @@ -193,7 +193,7 @@ FILE fqName: fileName:/castsInsideCoroutineInference.kt $this: VALUE_PARAMETER name: type:kotlin.Any FUN name:flow visibility:public modality:FINAL (block:@[ExtensionFunctionType] kotlin.coroutines.SuspendFunction1<.FlowCollector.flow>, kotlin.Unit>) returnType:.Flow.flow> annotations: - OptIn(markerClass = [CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB ANNOTATION_CLASS name:ExperimentalTypeInference modality:FINAL visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass]) + OptIn(markerClass = [CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB ANNOTATION_CLASS name:ExperimentalTypeInference modality:OPEN visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass]) TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] VALUE_PARAMETER name:block index:0 type:@[ExtensionFunctionType] kotlin.coroutines.SuspendFunction1<.FlowCollector.flow>, kotlin.Unit> annotations: @@ -203,7 +203,7 @@ FILE fqName: fileName:/castsInsideCoroutineInference.kt CALL 'public final fun TODO (): kotlin.Nothing [inline] declared in kotlin.StandardKt' type=kotlin.Nothing origin=null FUN name:flowScope visibility:public modality:FINAL (block:@[ExtensionFunctionType] kotlin.coroutines.SuspendFunction1<.CoroutineScope, R of .flowScope>) returnType:R of .flowScope [suspend] annotations: - OptIn(markerClass = [CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB ANNOTATION_CLASS name:ExperimentalTypeInference modality:FINAL visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass]) + OptIn(markerClass = [CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB ANNOTATION_CLASS name:ExperimentalTypeInference modality:OPEN visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass]) TYPE_PARAMETER name:R index:0 variance: superTypes:[kotlin.Any?] VALUE_PARAMETER name:block index:0 type:@[ExtensionFunctionType] kotlin.coroutines.SuspendFunction1<.CoroutineScope, R of .flowScope> annotations: @@ -311,7 +311,7 @@ FILE fqName: fileName:/castsInsideCoroutineInference.kt $this: VALUE_PARAMETER name: type:kotlin.Any FUN name:produce visibility:public modality:FINAL ($receiver:.CoroutineScope, block:@[ExtensionFunctionType] kotlin.coroutines.SuspendFunction1<.ProducerScope.produce>, kotlin.Unit>) returnType:.ReceiveChannel.produce> annotations: - OptIn(markerClass = [CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB ANNOTATION_CLASS name:ExperimentalTypeInference modality:FINAL visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass]) + OptIn(markerClass = [CLASS_REFERENCE 'CLASS IR_EXTERNAL_DECLARATION_STUB ANNOTATION_CLASS name:ExperimentalTypeInference modality:OPEN visibility:public superTypes:[kotlin.Annotation]' type=kotlin.reflect.KClass]) TYPE_PARAMETER name:E index:0 variance: superTypes:[kotlin.Any?] $receiver: VALUE_PARAMETER name: type:.CoroutineScope VALUE_PARAMETER name:block index:0 type:@[ExtensionFunctionType] kotlin.coroutines.SuspendFunction1<.ProducerScope.produce>, kotlin.Unit>