From c097e6ee3e4a2723b6bb481aced2b7cd816b082c Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 10 Dec 2014 16:05:51 +0300 Subject: [PATCH] After approximation interpret Contr<*> as Contr not Contr --- compiler/testData/capturedTypeApproximation/contravariant.kt | 2 +- .../org/jetbrains/jet/lang/types/CapturedTypeApproximation.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/testData/capturedTypeApproximation/contravariant.kt b/compiler/testData/capturedTypeApproximation/contravariant.kt index 68f95b0ba34..fd826a41ef3 100644 --- a/compiler/testData/capturedTypeApproximation/contravariant.kt +++ b/compiler/testData/capturedTypeApproximation/contravariant.kt @@ -8,4 +8,4 @@ fun foo(a: Contr) {} // T captures 'out Int' // lower: Contr -// upper: Contr +// upper: Contr diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/CapturedTypeApproximation.kt b/core/descriptors/src/org/jetbrains/jet/lang/types/CapturedTypeApproximation.kt index ff99a29c884..94e23bec8c5 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/CapturedTypeApproximation.kt +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/CapturedTypeApproximation.kt @@ -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") }