[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
This commit is contained in:
committed by
Mikhail Glukhikh
parent
a453ed50fa
commit
71ca1aa608
+11
-6
@@ -205,20 +205,25 @@ object NewCommonSuperTypeCalculator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val argument =
|
// This is used for folding recursive types like Inv<Inv<*>> into Inv<*>
|
||||||
if (thereIsStar || typeProjections.isEmpty()) {
|
fun collapseRecursiveArgumentIfPossible(argument: TypeArgumentMarker): TypeArgumentMarker {
|
||||||
createStarProjection(parameter)
|
if (argument.isStarProjection()) return argument
|
||||||
} else {
|
|
||||||
val argument = calculateArgument(parameter, typeProjections, depth)
|
|
||||||
val argumentType = argument.getType().asSimpleType()
|
val argumentType = argument.getType().asSimpleType()
|
||||||
val argumentConstructor = argumentType?.typeConstructor()
|
val argumentConstructor = argumentType?.typeConstructor()
|
||||||
if (argument.getVariance() == TypeVariance.OUT && argumentConstructor == constructor && argumentType.asArgumentList()[index].isStarProjection()) {
|
return if (argument.getVariance() == TypeVariance.OUT && argumentConstructor == constructor && argumentType.asArgumentList()[index].isStarProjection()) {
|
||||||
createStarProjection(parameter)
|
createStarProjection(parameter)
|
||||||
} else {
|
} else {
|
||||||
argument
|
argument
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val argument =
|
||||||
|
if (thereIsStar || typeProjections.isEmpty()) {
|
||||||
|
createStarProjection(parameter)
|
||||||
|
} else {
|
||||||
|
collapseRecursiveArgumentIfPossible(calculateArgument(parameter, typeProjections, depth))
|
||||||
|
}
|
||||||
|
|
||||||
arguments.add(argument)
|
arguments.add(argument)
|
||||||
}
|
}
|
||||||
return createSimpleType(constructor, arguments, nullable = false)
|
return createSimpleType(constructor, arguments, nullable = false)
|
||||||
|
|||||||
Reference in New Issue
Block a user