From 71ca1aa6080209220ed8b4cb5d4855ec16743c39 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Tue, 23 Jul 2019 16:43:38 +0300 Subject: [PATCH] [Type system] Fix algorithm of folding recursive types There was a problem when we get type from type projection even if it is a star projection what is meaningless. Now we try to fold argument only if it's not a star projection --- .../calls/NewCommonSuperTypeCalculator.kt | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt index b8c46513521..4167074a11a 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/NewCommonSuperTypeCalculator.kt @@ -205,18 +205,23 @@ object NewCommonSuperTypeCalculator { } } + // This is used for folding recursive types like Inv> into Inv<*> + fun collapseRecursiveArgumentIfPossible(argument: TypeArgumentMarker): TypeArgumentMarker { + if (argument.isStarProjection()) return argument + val argumentType = argument.getType().asSimpleType() + val argumentConstructor = argumentType?.typeConstructor() + return if (argument.getVariance() == TypeVariance.OUT && argumentConstructor == constructor && argumentType.asArgumentList()[index].isStarProjection()) { + createStarProjection(parameter) + } else { + argument + } + } + val argument = if (thereIsStar || typeProjections.isEmpty()) { createStarProjection(parameter) } else { - val argument = calculateArgument(parameter, typeProjections, depth) - val argumentType = argument.getType().asSimpleType() - val argumentConstructor = argumentType?.typeConstructor() - if (argument.getVariance() == TypeVariance.OUT && argumentConstructor == constructor && argumentType.asArgumentList()[index].isStarProjection()) { - createStarProjection(parameter) - } else { - argument - } + collapseRecursiveArgumentIfPossible(calculateArgument(parameter, typeProjections, depth)) } arguments.add(argument)