Minor cleanup of approximateCapturedType comments/code
This commit is contained in:
committed by
Space Team
parent
44dcae2090
commit
f3523edb61
+9
-5
@@ -327,17 +327,21 @@ abstract class AbstractTypeApproximator(
|
|||||||
// Thanks to it, K1 builds the star projection type as AbstractField<*> and no other approximation is needed.
|
// Thanks to it, K1 builds the star projection type as AbstractField<*> and no other approximation is needed.
|
||||||
//
|
//
|
||||||
// In turn, K2 never makes such a thing (K2 star projection has no associated type).
|
// In turn, K2 never makes such a thing (K2 star projection has no associated type).
|
||||||
// Instead, it resolves y.field as CapturedType(*) C (see usage one line below v ),
|
// Instead, it resolves y.field as CapturedType(*) C (see usage one line below),
|
||||||
// and the constructor of this captured type has a star projection and a supertype of AbstractField(C)
|
// and the constructor of this captured type has a star projection and a supertype of `AbstractField<C>`.
|
||||||
|
//
|
||||||
// Without this replacement, the type approximator currently cannot handle such a situation properly
|
// Without this replacement, the type approximator currently cannot handle such a situation properly
|
||||||
// and builds AbstractField<AbstractField<AbstractField<Any?>>>.
|
// and builds AbstractField<AbstractField<AbstractField<Any?>>>.
|
||||||
// The check it == type here is intended to find a recursion inside a captured type.
|
// The check it == type here is intended to find a recursion inside a captured type.
|
||||||
// A similar replacement for baseSubType looks unnecessary, no hits in the tests.
|
// A similar replacement for baseSubType looks unnecessary, no hits in the tests.
|
||||||
val replacedSuperType = if (isK2 && toSuper && baseSuperType.getArguments().any { it == capturedType }) {
|
val replacedSuperType = if (isK2 && toSuper && baseSuperType.getArguments().any { it == capturedType }) {
|
||||||
baseSuperType.replaceArguments {
|
baseSuperType.replaceArguments {
|
||||||
// It's possible to use the stub here, because K2 star projection is an object and
|
when {
|
||||||
// in fact this parameter is never used
|
it != capturedType -> it
|
||||||
if (it != capturedType) it else createStarProjection(TypeParameterMarkerStubForK2StarProjection)
|
// It's possible to use the stub here, because K2 star projection is an object and
|
||||||
|
// in fact this parameter is never used
|
||||||
|
else -> createStarProjection(TypeParameterMarkerStubForK2StarProjection)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else baseSuperType
|
} else baseSuperType
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user