diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/typeMappingUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/typeMappingUtil.kt index bf215f52080..d2f6e2382d2 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/typeMappingUtil.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/typeMappingUtil.kt @@ -26,7 +26,6 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.load.kotlin.TypeMappingMode import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.JvmStandardClassIds.JVM_SUPPRESS_WILDCARDS_ANNOTATION_FQ_NAME -import org.jetbrains.kotlin.name.JvmStandardClassIds.JVM_WILDCARD_ANNOTATION_FQ_NAME import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.descriptorUtil.firstOverridden import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull @@ -35,6 +34,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.propertyIfAccessor import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext import org.jetbrains.kotlin.types.Variance +import org.jetbrains.kotlin.types.suppressWildcardsMode import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext import org.jetbrains.kotlin.types.checker.convertVariance import org.jetbrains.kotlin.types.getEffectiveVariance @@ -91,31 +91,6 @@ private val METHODS_WITH_DECLARATION_SITE_WILDCARDS = setOf( FqNames.mutableMap.child("putAll") ) -fun TypeMappingMode.updateArgumentModeFromAnnotations( - type: KotlinTypeMarker, typeSystem: TypeSystemCommonBackendContext -): TypeMappingMode { - type.suppressWildcardsMode(typeSystem)?.let { - return TypeMappingMode.createWithConstantDeclarationSiteWildcardsMode( - skipDeclarationSiteWildcards = it, - isForAnnotationParameter = isForAnnotationParameter, - needInlineClassWrapping = needInlineClassWrapping, - mapTypeAliases = mapTypeAliases - ) - } - - if (with(typeSystem) { type.hasAnnotation(JVM_WILDCARD_ANNOTATION_FQ_NAME) }) { - return TypeMappingMode.createWithConstantDeclarationSiteWildcardsMode( - skipDeclarationSiteWildcards = false, - isForAnnotationParameter = isForAnnotationParameter, - fallbackMode = this, - needInlineClassWrapping = needInlineClassWrapping, - mapTypeAliases = mapTypeAliases - ) - } - - return this -} - internal fun extractTypeMappingModeFromAnnotation( callableDescriptor: CallableDescriptor?, outerType: KotlinType, @@ -150,12 +125,6 @@ private fun DeclarationDescriptor.suppressWildcardsMode(): Boolean? = it.annotations.findAnnotation(JVM_SUPPRESS_WILDCARDS_ANNOTATION_FQ_NAME) }.firstOrNull()?.suppressWildcardsMode() -private fun KotlinTypeMarker.suppressWildcardsMode(typeSystem: TypeSystemCommonBackendContext): Boolean? = - with(typeSystem) { - if (hasAnnotation(JVM_SUPPRESS_WILDCARDS_ANNOTATION_FQ_NAME)) - getAnnotationFirstArgumentValue(JVM_SUPPRESS_WILDCARDS_ANNOTATION_FQ_NAME) as? Boolean ?: true - else null - } private fun AnnotationDescriptor.suppressWildcardsMode(): Boolean? = allValueArguments.values.firstOrNull()?.value as? Boolean ?: true diff --git a/core/compiler.common.jvm/src/org/jetbrains/kotlin/types/typeMappingUtil.kt b/core/compiler.common.jvm/src/org/jetbrains/kotlin/types/typeMappingUtil.kt new file mode 100644 index 00000000000..202a6034a2f --- /dev/null +++ b/core/compiler.common.jvm/src/org/jetbrains/kotlin/types/typeMappingUtil.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +@file:JvmName("TypeMappingUtil") + +package org.jetbrains.kotlin.types + +import org.jetbrains.kotlin.load.kotlin.TypeMappingMode +import org.jetbrains.kotlin.name.JvmStandardClassIds +import org.jetbrains.kotlin.name.JvmStandardClassIds.JVM_SUPPRESS_WILDCARDS_ANNOTATION_FQ_NAME +import org.jetbrains.kotlin.types.model.KotlinTypeMarker + +fun TypeMappingMode.updateArgumentModeFromAnnotations( + type: KotlinTypeMarker, typeSystem: TypeSystemCommonBackendContext +): TypeMappingMode { + type.suppressWildcardsMode(typeSystem)?.let { + return TypeMappingMode.createWithConstantDeclarationSiteWildcardsMode( + skipDeclarationSiteWildcards = it, + isForAnnotationParameter = isForAnnotationParameter, + needInlineClassWrapping = needInlineClassWrapping, + mapTypeAliases = mapTypeAliases + ) + } + + if (with(typeSystem) { type.hasAnnotation(JvmStandardClassIds.JVM_WILDCARD_ANNOTATION_FQ_NAME) }) { + return TypeMappingMode.createWithConstantDeclarationSiteWildcardsMode( + skipDeclarationSiteWildcards = false, + isForAnnotationParameter = isForAnnotationParameter, + fallbackMode = this, + needInlineClassWrapping = needInlineClassWrapping, + mapTypeAliases = mapTypeAliases + ) + } + + return this +} + +fun KotlinTypeMarker.suppressWildcardsMode(typeSystem: TypeSystemCommonBackendContext): Boolean? = + with(typeSystem) { + if (hasAnnotation(JVM_SUPPRESS_WILDCARDS_ANNOTATION_FQ_NAME)) + getAnnotationFirstArgumentValue(JVM_SUPPRESS_WILDCARDS_ANNOTATION_FQ_NAME) as? Boolean ?: true + else null + } diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ErrorTypeCorrector.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ErrorTypeCorrector.kt index 9784f3d10f6..0b1fc254a59 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ErrorTypeCorrector.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ErrorTypeCorrector.kt @@ -20,7 +20,6 @@ import com.intellij.psi.util.PsiTreeUtil import com.sun.tools.javac.code.BoundKind import com.sun.tools.javac.tree.JCTree import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper -import org.jetbrains.kotlin.codegen.state.updateArgumentModeFromAnnotations import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.kapt3.base.javac.kaptError import org.jetbrains.kotlin.kapt3.base.mapJList