K2/Java/enhancement: implement wildcards replacement with flexible bounds
This commit in fact changes two very related places: - first, it implements forgotten 'enhancedForWarnings' in K2 enhancement - second, it repeats KT-48515 fix for K2 while enhancing wildcards #KT-65594 Fixed Related to KT-48515, KT-63746
This commit is contained in:
committed by
Space Team
parent
5b0cb5c9db
commit
40c4e865c7
+1
-1
@@ -891,7 +891,7 @@ private class EnhancementSignatureParts(
|
||||
get() = ((this as? ConeLookupTagBasedType)?.lookupTag as? ConeClassLikeLookupTag)?.classId?.asSingleFqName()?.toUnsafe()
|
||||
|
||||
override val KotlinTypeMarker.enhancedForWarnings: KotlinTypeMarker?
|
||||
get() = null // TODO: implement enhancement for warnings
|
||||
get() = (this as ConeKotlinType).enhancedTypeForWarning
|
||||
|
||||
override fun KotlinTypeMarker.isEqual(other: KotlinTypeMarker): Boolean =
|
||||
AbstractTypeChecker.equalTypes(session.typeContext, this, other)
|
||||
|
||||
@@ -8,7 +8,9 @@ package org.jetbrains.kotlin.fir.java.enhancement
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration
|
||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
@@ -160,17 +162,31 @@ private fun ConeLookupTagBasedType.enhanceInflexibleType(
|
||||
}
|
||||
|
||||
var globalArgIndex = index + 1
|
||||
val enhancedArguments = typeArguments.map { arg ->
|
||||
val argIndex = globalArgIndex.also { globalArgIndex += subtreeSizes[it] }
|
||||
arg.type?.enhanceConeKotlinType(session, qualifiers, argIndex, subtreeSizes, convertErrorsToWarnings = convertNestedErrorsToWarnings)
|
||||
?.let {
|
||||
when (arg.kind) {
|
||||
ProjectionKind.IN -> ConeKotlinTypeProjectionIn(it)
|
||||
ProjectionKind.OUT -> ConeKotlinTypeProjectionOut(it)
|
||||
ProjectionKind.STAR -> ConeStarProjection
|
||||
ProjectionKind.INVARIANT -> it
|
||||
}
|
||||
val enhancedArguments = typeArguments.mapIndexed { currentArgLocalIndex, arg ->
|
||||
val currentArgGlobalIndex = globalArgIndex.also { globalArgIndex += subtreeSizes[it] }
|
||||
if (arg.type == null && qualifiers(currentArgGlobalIndex).nullability == NullabilityQualifier.FORCE_FLEXIBILITY) {
|
||||
// Given `C<T extends @Nullable V>`, unannotated `C<?>` is `C<out (V..V?)>`.
|
||||
val typeParameters = (this.lookupTag.toSymbol(session)?.fir as? FirClassLikeDeclaration)?.typeParameters
|
||||
if (typeParameters != null) {
|
||||
val bound = typeParameters[currentArgLocalIndex].symbol.fir.bounds.first().coneType
|
||||
return@mapIndexed ConeKotlinTypeProjectionOut(
|
||||
ConeFlexibleType(
|
||||
bound.lowerBoundIfFlexible().withNullability(ConeNullability.NOT_NULL, session.typeContext),
|
||||
bound.upperBoundIfFlexible().withNullability(ConeNullability.NULLABLE, session.typeContext)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
arg.type?.enhanceConeKotlinType(
|
||||
session, qualifiers, currentArgGlobalIndex, subtreeSizes, convertErrorsToWarnings = convertNestedErrorsToWarnings
|
||||
)?.let {
|
||||
when (arg.kind) {
|
||||
ProjectionKind.IN -> ConeKotlinTypeProjectionIn(it)
|
||||
ProjectionKind.OUT -> ConeKotlinTypeProjectionOut(it)
|
||||
ProjectionKind.STAR -> ConeStarProjection
|
||||
ProjectionKind.INVARIANT -> it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val shouldAddAttribute = nullabilityFromQualifiers == NullabilityQualifier.NOT_NULL && !hasEnhancedNullability
|
||||
|
||||
Reference in New Issue
Block a user