From c85329905ccd491bd8112b98c2b56d0d5ec69f04 Mon Sep 17 00:00:00 2001 From: pyos Date: Mon, 16 Aug 2021 14:32:44 +0200 Subject: [PATCH] FE: remove `?` enhancement code that is never used Using `starProjectionType` to enhance `?` is pointless because 1. we explicitly ignore nullability annotations for `?` below; 2. mutability is irrelevant; 3. `starProjectionType` never returns references to other type parameters due to how the type substitutor works. --- .../typeEnhancement/AbstractSignatureParts.kt | 15 ++++++--------- .../java/typeEnhancement/signatureEnhancement.kt | 3 --- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/AbstractSignatureParts.kt b/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/AbstractSignatureParts.kt index 4885b114d02..6558f27e44c 100644 --- a/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/AbstractSignatureParts.kt +++ b/core/compiler.common.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/AbstractSignatureParts.kt @@ -34,7 +34,6 @@ abstract class AbstractSignatureParts { abstract val KotlinTypeMarker.fqNameUnsafe: FqNameUnsafe? abstract fun KotlinTypeMarker.isEqual(other: KotlinTypeMarker): Boolean - abstract val TypeParameterMarker.starProjectedType: KotlinTypeMarker? abstract val TypeParameterMarker.isFromJava: Boolean open val KotlinTypeMarker.isNotNullTypeParameterCompat: Boolean @@ -71,11 +70,11 @@ abstract class AbstractSignatureParts { } val isHeadTypeConstructor = typeParameterForArgument == null - val typeOrBound = type ?: typeParameterForArgument?.starProjectedType ?: return JavaTypeQualifiers.NONE - val typeParameterUse = with(typeSystem) { typeOrBound.typeConstructor().getTypeParameterClassifier() } + val typeAnnotations = type?.annotations ?: emptyList() + val typeParameterUse = with(typeSystem) { type?.typeConstructor()?.getTypeParameterClassifier() } val typeParameterBounds = containerApplicabilityType == AnnotationQualifierApplicabilityType.TYPE_PARAMETER_BOUNDS val composedAnnotation = when { - !isHeadTypeConstructor -> typeOrBound.annotations + !isHeadTypeConstructor -> typeAnnotations !typeParameterBounds && enableImprovementsInStrictMode -> // We don't apply container type use annotations to avoid double applying them like with arrays: // @NotNull Integer [] f15(); @@ -83,14 +82,13 @@ abstract class AbstractSignatureParts { // and to entire array (as METHOD annotation). // In other words, we prefer TYPE_USE target of an annotation, and apply the annotation only according to it, if it's present. // See KT-24392 for more details. - containerAnnotations.filter { !annotationTypeQualifierResolver.isTypeUseAnnotation(it) } + typeOrBound.annotations - else -> containerAnnotations + typeOrBound.annotations + containerAnnotations.filter { !annotationTypeQualifierResolver.isTypeUseAnnotation(it) } + typeAnnotations + else -> containerAnnotations + typeAnnotations } val annotationsMutability = annotationTypeQualifierResolver.extractMutability(composedAnnotation) val annotationsNullability = annotationTypeQualifierResolver.extractNullability(composedAnnotation) { forceWarning } - - if (type != null && annotationsNullability != null) { + if (annotationsNullability != null) { return JavaTypeQualifiers( annotationsNullability.qualifier, annotationsMutability, annotationsNullability.qualifier == NullabilityQualifier.NOT_NULL && typeParameterUse != null, @@ -98,7 +96,6 @@ abstract class AbstractSignatureParts { ) } - // TODO: check whether the code below works properly for star projections (when typeOrBound != type) val applicabilityType = when { isHeadTypeConstructor || typeParameterBounds -> containerApplicabilityType else -> AnnotationQualifierApplicabilityType.TYPE_USE diff --git a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/signatureEnhancement.kt b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/signatureEnhancement.kt index 76898993d01..ef63d586e17 100644 --- a/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/signatureEnhancement.kt +++ b/core/descriptors.jvm/src/org/jetbrains/kotlin/load/java/typeEnhancement/signatureEnhancement.kt @@ -251,9 +251,6 @@ private class SignatureParts( override fun KotlinTypeMarker.isEqual(other: KotlinTypeMarker): Boolean = containerContext.components.kotlinTypeChecker.equalTypes(this as KotlinType, other as KotlinType) - override val TypeParameterMarker.starProjectedType: KotlinType - get() = (this as TypeParameterDescriptor).starProjectionType() - override val TypeParameterMarker.isFromJava: Boolean get() = this is LazyJavaTypeParameterDescriptor }