AA: honor wildcard suppression on type during type conversion

^KT-61734
This commit is contained in:
Jinseong Jeon
2024-02-22 14:50:09 -08:00
committed by teamcity
parent 94e5653eb7
commit d089db5a45
3 changed files with 17 additions and 3 deletions
@@ -73,6 +73,13 @@ internal class KtFe10PsiTypeProvider(
typeMapper.typeContext.getOptimalModeForReturnType(type.fe10Type, isAnnotationMethod)
KtTypeMappingMode.VALUE_PARAMETER ->
typeMapper.typeContext.getOptimalModeForValueParameter(type.fe10Type)
}.let { typeMappingMode ->
// Otherwise, i.e., if we won't skip type with no type arguments, flag overriding might bother a case like:
// @JvmSuppressWildcards(false) Long -> java.lang.Long, not long, even though it should be no-op!
if (type.fe10Type.arguments.isEmpty())
typeMappingMode
else
typeMappingMode.updateArgumentModeFromAnnotations(type.fe10Type, typeMapper.typeContext)
}
}
@@ -59,6 +59,7 @@ import org.jetbrains.kotlin.psi
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.psiUtil.parents
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
import org.jetbrains.kotlin.types.updateArgumentModeFromAnnotations
import java.text.StringCharacterIterator
internal class KtFirPsiTypeProvider(
@@ -89,6 +90,7 @@ internal class KtFirPsiTypeProvider(
private fun KtTypeMappingMode.toTypeMappingMode(type: KtType, isAnnotationMethod: Boolean): TypeMappingMode {
require(type is KtFirType)
val expandedType = type.coneType.fullyExpandedType(rootModuleSession)
return when (this) {
KtTypeMappingMode.DEFAULT -> TypeMappingMode.DEFAULT
KtTypeMappingMode.DEFAULT_UAST -> TypeMappingMode.DEFAULT_UAST
@@ -97,13 +99,18 @@ internal class KtFirPsiTypeProvider(
KtTypeMappingMode.SUPER_TYPE_KOTLIN_COLLECTIONS_AS_IS -> TypeMappingMode.SUPER_TYPE_KOTLIN_COLLECTIONS_AS_IS
KtTypeMappingMode.RETURN_TYPE_BOXED -> TypeMappingMode.RETURN_TYPE_BOXED
KtTypeMappingMode.RETURN_TYPE -> {
val expandedType = type.coneType.fullyExpandedType(rootModuleSession)
rootModuleSession.jvmTypeMapper.typeContext.getOptimalModeForReturnType(expandedType, isAnnotationMethod)
}
KtTypeMappingMode.VALUE_PARAMETER -> {
val expandedType = type.coneType.fullyExpandedType(rootModuleSession)
rootModuleSession.jvmTypeMapper.typeContext.getOptimalModeForValueParameter(expandedType)
}
}.let { typeMappingMode ->
// Otherwise, i.e., if we won't skip type with no type arguments, flag overriding might bother a case like:
// @JvmSuppressWildcards(false) Long -> java.lang.Long, not long, even though it should be no-op!
if (expandedType.typeArguments.isEmpty())
typeMappingMode
else
typeMappingMode.updateArgumentModeFromAnnotations(expandedType, rootModuleSession.jvmTypeMapper.typeContext)
}
}
@@ -1,2 +1,2 @@
KtType: @kotlin.jvm.JvmSuppressWildcards(suppress = true) (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition?)?
PsiType: PsiType:Function1<? super AnimatedContentTransitionScope<NavBackStackEntry>, ? extends EnterTransition>
PsiType: PsiType:Function1<AnimatedContentTransitionScope<NavBackStackEntry>, EnterTransition>