diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/typeAnnotationCollector.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/typeAnnotationCollector.kt index 2b31194463e..05453211b6d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/typeAnnotationCollector.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/typeAnnotationCollector.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.codegen import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.SourceElement import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.load.kotlin.FileBasedKotlinClass import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement @@ -99,8 +100,10 @@ abstract class TypeAnnotationCollector(val context: TypeSystemCommonBackendCo abstract fun KotlinTypeMarker.extractAnnotations(): List fun isCompiledToJvm8OrHigher(descriptor: ClassDescriptor?): Boolean = - (descriptor as? DeserializedClassDescriptor)?.let { classDescriptor -> - ((classDescriptor.source as? KotlinJvmBinarySourceElement)?.binaryClass as? FileBasedKotlinClass)?.classVersion ?: 0 >= Opcodes.V1_8 - } ?: true + (descriptor as? DeserializedClassDescriptor)?.let { classDescriptor -> isCompiledToJvm8OrHigher(classDescriptor.source) } + ?: true + fun isCompiledToJvm8OrHigher(source: SourceElement): Boolean = + (source !is KotlinJvmBinarySourceElement || + (source.binaryClass as? FileBasedKotlinClass)?.classVersion ?: 0 >= Opcodes.V1_8) } \ No newline at end of file diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/AnnotationCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/AnnotationCodegen.kt index 453bcb3189c..7c846bc8694 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/AnnotationCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/AnnotationCodegen.kt @@ -341,13 +341,18 @@ abstract class AnnotationCodegen( override fun KotlinTypeMarker.extractAnnotations(): List { require(this is IrType) return annotations.filter { - //We only generate annotations which have the TYPE_USE Java target. + // We only generate annotations which have the TYPE_USE Java target. // Those are type annotations which were compiled with JVM target bytecode version 1.8 or greater (it.annotationClass.origin != IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB && it.annotationClass.origin != IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB) || - isCompiledToJvm8OrHigher(it.annotationClass.descriptor) + it.annotationClass.isCompiledToJvm8OrHigher } } + + private val IrClass.isCompiledToJvm8OrHigher: Boolean + get() = + (origin == IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB || origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB) && + isCompiledToJvm8OrHigher(source) } }