Load contavariantly projected collections in Java as mutable
#KT-3068 Fixed
This commit is contained in:
+8
-2
@@ -146,8 +146,12 @@ class LazyJavaTypeResolver(
|
||||
|
||||
val kotlinDescriptor = javaToKotlin.mapJavaToKotlin(fqName) ?: return null
|
||||
|
||||
if (howThisTypeIsUsedEffectively == MEMBER_SIGNATURE_COVARIANT || howThisTypeIsUsedEffectively == SUPERTYPE) {
|
||||
if (javaToKotlin.isReadOnly(kotlinDescriptor)) {
|
||||
if (javaToKotlin.isReadOnly(kotlinDescriptor)) {
|
||||
if (howThisTypeIsUsedEffectively == MEMBER_SIGNATURE_COVARIANT
|
||||
|| howThisTypeIsUsedEffectively == SUPERTYPE
|
||||
// Convert (Mutable)List<in A> to MutableList<in A>
|
||||
// Same for (Mutable)Map<K, in V>
|
||||
|| javaType.typeArguments.lastOrNull().isSuperWildcard()) {
|
||||
return javaToKotlin.convertReadOnlyToMutable(kotlinDescriptor)
|
||||
}
|
||||
}
|
||||
@@ -155,6 +159,8 @@ class LazyJavaTypeResolver(
|
||||
return kotlinDescriptor
|
||||
}
|
||||
|
||||
private fun JavaType?.isSuperWildcard(): Boolean = (this as? JavaWildcardType)?.let { it.bound != null && !it.isExtends } ?: false
|
||||
|
||||
private fun isRaw(): Boolean {
|
||||
if (javaType.isRaw) return true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user