Implement inferring materialized self types through a default type in ResultTypeResolver

This commit is contained in:
Victor Petukhov
2021-07-07 14:00:09 +03:00
parent 3787099a38
commit c2cf2f36cd
13 changed files with 103 additions and 60 deletions
@@ -22,10 +22,7 @@ import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor
import org.jetbrains.kotlin.types.model.*
import org.jetbrains.kotlin.utils.addToStdlib.cast
class ClassicTypeSystemContextForCS(
override val builtIns: KotlinBuiltIns,
private val languageVersionSettings: LanguageVersionSettings
) : TypeSystemInferenceExtensionContextDelegate,
class ClassicTypeSystemContextForCS(override val builtIns: KotlinBuiltIns) : TypeSystemInferenceExtensionContextDelegate,
ClassicTypeSystemContext,
BuiltInsProvider {
@@ -48,16 +45,13 @@ class ClassicTypeSystemContextForCS(
require(lowerType is UnwrappedType?, lowerType::errorMessage)
require(constructorProjection is TypeProjectionBase, constructorProjection::errorMessage)
val isTypeInferenceForSelfTypesSupported =
languageVersionSettings.supportsFeature(LanguageFeature.TypeInferenceOnCallsWithSelfTypes)
@Suppress("UNCHECKED_CAST")
val newCapturedTypeConstructor = NewCapturedTypeConstructor(
constructorProjection,
constructorSupertypes as List<UnwrappedType>
)
return NewCapturedType(
if (isTypeInferenceForSelfTypesSupported) captureStatus else CaptureStatus.FOR_INCORPORATION,
captureStatus,
newCapturedTypeConstructor,
lowerType = lowerType
)
@@ -117,5 +111,5 @@ fun NewConstraintSystemImpl(
constraintInjector: ConstraintInjector,
builtIns: KotlinBuiltIns
): NewConstraintSystemImpl {
return NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns, constraintInjector.languageVersionSettings))
return NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns))
}
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.types.model.*
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
class SimpleConstraintSystemImpl(constraintInjector: ConstraintInjector, builtIns: KotlinBuiltIns) : SimpleConstraintSystem {
val system = NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns, constraintInjector.languageVersionSettings))
val system = NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns))
val csBuilder: ConstraintSystemBuilder =
system.getBuilder()
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.resolve.calls.components.ClassicTypeSystemContextFor
class TypeApproximator(
builtIns: KotlinBuiltIns,
languageVersionSettings: LanguageVersionSettings,
) : AbstractTypeApproximator(ClassicTypeSystemContextForCS(builtIns, languageVersionSettings), languageVersionSettings) {
) : AbstractTypeApproximator(ClassicTypeSystemContextForCS(builtIns), languageVersionSettings) {
fun approximateDeclarationType(baseType: KotlinType, local: Boolean): UnwrappedType {
if (!languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) return baseType.unwrap()