From 6c27a4911409660feab78a24c3b332125f4e91ed Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Wed, 6 Dec 2017 16:29:47 +0300 Subject: [PATCH] [NI] Use effective variance for equal approximated type It's totally safe from the point of type system and reduces extra `out` projections that can add problems with subtyping --- .../src/org/jetbrains/kotlin/types/TypeApproximator.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt b/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt index 9e73e627277..1e6cd4014fa 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt @@ -406,7 +406,12 @@ class TypeApproximator { } } - newArguments[index] = TypeProjectionImpl(Variance.OUT_VARIANCE, approximatedSuperType) + if (NewKotlinTypeChecker.equalTypes(argumentType, approximatedSuperType)) { + newArguments[index] = approximatedSuperType.asTypeProjection() + } + else { + newArguments[index] = TypeProjectionImpl(Variance.OUT_VARIANCE, approximatedSuperType) + } } } }