Fix loading Java type arguments

Type arguments with use variance in java contradicting to Kotlin declaration-site variance should be loaded as star-projections

 #KT-11492 Fixed
This commit is contained in:
Denis Zharkov
2016-03-18 14:53:25 +03:00
parent 838fcf9a57
commit c3e44ec199
4 changed files with 67 additions and 2 deletions
@@ -224,12 +224,13 @@ class LazyJavaTypeResolver(
return when (javaType) {
is JavaWildcardType -> {
val bound = javaType.bound
if (bound == null)
val projectionKind = if (javaType.isExtends) OUT_VARIANCE else IN_VARIANCE
if (bound == null || projectionKind.isConflictingArgumentFor(typeParameter))
makeStarProjection(typeParameter, attr)
else {
createProjection(
type = transformJavaType(bound, UPPER_BOUND.toAttributes()),
projectionKind = if (javaType.isExtends) OUT_VARIANCE else IN_VARIANCE,
projectionKind = projectionKind,
typeParameterDescriptor = typeParameter
)
}
@@ -238,6 +239,11 @@ class LazyJavaTypeResolver(
}
}
private fun Variance.isConflictingArgumentFor(typeParameter: TypeParameterDescriptor): Boolean {
if (typeParameter.variance == INVARIANT) return false
return this != typeParameter.variance
}
override fun getCapabilities(): TypeCapabilities = if (isRaw()) RawTypeCapabilities else TypeCapabilities.NONE
private val nullable = c.storageManager.createLazyValue l@ {