Do not create redundant special variance when enhancing types
#KT-8538 Fixed
This commit is contained in:
+6
-5
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.types.Variance.INVARIANT
|
||||
import org.jetbrains.kotlin.types.Variance.IN_VARIANCE
|
||||
import org.jetbrains.kotlin.types.Variance.OUT_VARIANCE
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||
import org.jetbrains.kotlin.types.typeUtil.createProjection
|
||||
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import java.util.HashSet
|
||||
@@ -247,11 +248,11 @@ class LazyJavaTypeResolver(
|
||||
if (bound == null)
|
||||
makeStarProjection(typeParameter, attr)
|
||||
else {
|
||||
var projectionKind = if (javaType.isExtends()) OUT_VARIANCE else IN_VARIANCE
|
||||
if (projectionKind == typeParameter.getVariance()) {
|
||||
projectionKind = Variance.INVARIANT
|
||||
}
|
||||
TypeProjectionImpl(projectionKind, transformJavaType(bound, UPPER_BOUND.toAttributes()))
|
||||
createProjection(
|
||||
type = transformJavaType(bound, UPPER_BOUND.toAttributes()),
|
||||
projectionKind = if (javaType.isExtends()) OUT_VARIANCE else IN_VARIANCE,
|
||||
typeParameterDescriptor = typeParameter
|
||||
)
|
||||
}
|
||||
}
|
||||
else -> TypeProjectionImpl(INVARIANT, transformJavaType(javaType, attr))
|
||||
|
||||
+6
-6
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.load.java.typeEnhacement.NullabilityQualifier.NULLAB
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.createProjection
|
||||
|
||||
// The index in the lambda is the position of the type component:
|
||||
// Example: for `A<B, C<D, E>>`, indices go as follows: `0 - A<...>, 1 - B, 2 - C<D, E>, 3 - D, 4 - E`,
|
||||
@@ -74,6 +75,8 @@ private fun JetType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers, i
|
||||
val effectiveQualifiers = qualifiers(index)
|
||||
val (enhancedClassifier, enhancedMutabilityAnnotations) = originalClass.enhanceMutability(effectiveQualifiers, position)
|
||||
|
||||
val typeConstructor = enhancedClassifier.typeConstructor
|
||||
|
||||
var globalArgIndex = index + 1
|
||||
val enhancedArguments = getArguments().mapIndexed {
|
||||
localArgIndex, arg ->
|
||||
@@ -84,10 +87,7 @@ private fun JetType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers, i
|
||||
else {
|
||||
val (enhancedType, subtreeSize) = arg.getType().enhancePossiblyFlexible(qualifiers, globalArgIndex)
|
||||
globalArgIndex += subtreeSize
|
||||
TypeProjectionImpl(
|
||||
arg.getProjectionKind(),
|
||||
enhancedType
|
||||
)
|
||||
createProjection(enhancedType, arg.projectionKind, typeParameterDescriptor = typeConstructor.parameters[localArgIndex])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,12 +99,12 @@ private fun JetType.enhanceInflexible(qualifiers: (Int) -> JavaTypeQualifiers, i
|
||||
).filterNotNull().compositeAnnotationsOrSingle()
|
||||
|
||||
val (newSubstitution, substitutedEnhancedArgs) = computeNewSubstitutionAndArguments(
|
||||
enhancedClassifier.typeConstructor.parameters, enhancedArguments
|
||||
typeConstructor.parameters, enhancedArguments
|
||||
)
|
||||
|
||||
val enhancedType = JetTypeImpl(
|
||||
newAnnotations,
|
||||
enhancedClassifier.getTypeConstructor(),
|
||||
typeConstructor,
|
||||
enhancedNullability,
|
||||
substitutedEnhancedArgs,
|
||||
newSubstitution,
|
||||
|
||||
Reference in New Issue
Block a user