After approximation interpret Contr<*> as Contr<Nothing>

not Contr<out Any?>
This commit is contained in:
Svetlana Isakova
2014-12-10 16:05:51 +03:00
parent 14a53a105b
commit c097e6ee3e
2 changed files with 3 additions and 2 deletions
@@ -8,4 +8,4 @@ fun foo<T>(a: Contr<T>) {}
// T captures 'out Int'
// lower: Contr<Int>
// upper: Contr<out Any?>
// upper: Contr<Nothing>
@@ -58,7 +58,8 @@ private fun TypeArgument.toTypeProjection(): TypeProjection {
fun removeProjectionIfRedundant(variance: Variance) = if (variance == typeParameter.getVariance()) Variance.INVARIANT else variance
return when {
inProjection == outProjection -> TypeProjectionImpl(inProjection)
inProjection == NOTHING || inProjection == NULLABLE_NOTHING -> TypeProjectionImpl(removeProjectionIfRedundant(Variance.OUT_VARIANCE), outProjection)
(inProjection == NOTHING || inProjection == NULLABLE_NOTHING) && typeParameter.getVariance() != Variance.IN_VARIANCE ->
TypeProjectionImpl(removeProjectionIfRedundant(Variance.OUT_VARIANCE), outProjection)
outProjection == NULLABLE_ANY -> TypeProjectionImpl(removeProjectionIfRedundant(Variance.IN_VARIANCE), inProjection)
else -> throw AssertionError("Enhanced type projection can't be converted to type projection: $this")
}