Put the type inference on calls with self types under the compiler flag

This commit is contained in:
Victor Petukhov
2021-07-06 13:56:28 +03:00
parent 51c5a54e31
commit 3787099a38
30 changed files with 365 additions and 50 deletions
@@ -6,6 +6,8 @@
package org.jetbrains.kotlin.resolve.calls.components
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector
import org.jetbrains.kotlin.resolve.calls.inference.components.EmptySubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
@@ -20,7 +22,10 @@ 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) : TypeSystemInferenceExtensionContextDelegate,
class ClassicTypeSystemContextForCS(
override val builtIns: KotlinBuiltIns,
private val languageVersionSettings: LanguageVersionSettings
) : TypeSystemInferenceExtensionContextDelegate,
ClassicTypeSystemContext,
BuiltInsProvider {
@@ -43,13 +48,16 @@ class ClassicTypeSystemContextForCS(override val builtIns: KotlinBuiltIns) : Typ
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(
captureStatus,
if (isTypeInferenceForSelfTypesSupported) captureStatus else CaptureStatus.FOR_INCORPORATION,
newCapturedTypeConstructor,
lowerType = lowerType
)
@@ -109,5 +117,5 @@ fun NewConstraintSystemImpl(
constraintInjector: ConstraintInjector,
builtIns: KotlinBuiltIns
): NewConstraintSystemImpl {
return NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns))
return NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns, constraintInjector.languageVersionSettings))
}
@@ -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))
val system = NewConstraintSystemImpl(constraintInjector, ClassicTypeSystemContextForCS(builtIns, constraintInjector.languageVersionSettings))
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) {
) : AbstractTypeApproximator(ClassicTypeSystemContextForCS(builtIns, languageVersionSettings), languageVersionSettings) {
fun approximateDeclarationType(baseType: KotlinType, local: Boolean): UnwrappedType {
if (!languageVersionSettings.supportsFeature(LanguageFeature.NewInference)) return baseType.unwrap()