Load contavariantly projected collections in Java as mutable

#KT-3068 Fixed
This commit is contained in:
Denis Zharkov
2016-03-18 15:07:43 +03:00
parent e54b25a35a
commit 838fcf9a57
8 changed files with 23 additions and 12 deletions
@@ -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