NI: In subtyping do not intersect arguments for non-covariant types
It partially reverts 7898922066
because it's not obvious that it's a safe operation
for invariant/contravariant types.
Also, there's a necessary fix in prepareReceiverRegardingCaptureTypes
to make types order stable
Otherwise test bareTypesWithStarProjections becomes flaky.
Also, the changes in bareTypesWithStarProjections.kt are also expected
because the type of the expression `coneSymbol` after the second "if" is
FirVariableSymbol<*> & FirPropertySymbol & AbstractFirBasedSymbol<*>
thus we fix D in the call `coneSymbol.phasedFir()` to FirVariableSymbol<*>
because it's the first type in the list
(see the next line after the last changed in AbstractTypeChecker)
This commit is contained in:
@@ -270,7 +270,10 @@ object AbstractTypeChecker {
|
||||
|
||||
else -> { // at least 2 supertypes with same constructors. Such case is rare
|
||||
val newArguments = ArgumentList(superConstructor.parametersCount())
|
||||
var anyNonOutParameter = false
|
||||
for (index in 0 until superConstructor.parametersCount()) {
|
||||
anyNonOutParameter = anyNonOutParameter || superConstructor.getParameter(index).getVariance() != TypeVariance.OUT
|
||||
if (anyNonOutParameter) continue
|
||||
val allProjections = supertypesWithSameConstructor.map {
|
||||
it.getArgumentOrNull(index)?.takeIf { it.getVariance() == TypeVariance.INV }?.getType()
|
||||
?: error("Incorrect type: $it, subType: $subType, superType: $superType")
|
||||
@@ -281,7 +284,7 @@ object AbstractTypeChecker {
|
||||
newArguments.add(intersection)
|
||||
}
|
||||
|
||||
if (isSubtypeForSameConstructor(newArguments, superType)) return true
|
||||
if (!anyNonOutParameter && isSubtypeForSameConstructor(newArguments, superType)) return true
|
||||
|
||||
return supertypesWithSameConstructor.any { isSubtypeForSameConstructor(it.asArgumentList(), superType) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user