[Minor] Rename fresh variable substitutor in resolved atom
This commit is contained in:
+3
-3
@@ -53,14 +53,14 @@ class DelegatedPropertyInferenceSession(
|
||||
?: builtIns.nullableNothingType
|
||||
|
||||
val valueParameterForThis = descriptor.valueParameters.getOrNull(0) ?: return
|
||||
val substitutedType = substitutor.safeSubstitute(valueParameterForThis.type.unwrap())
|
||||
val substitutedType = freshVariablesSubstitutor.safeSubstitute(valueParameterForThis.type.unwrap())
|
||||
commonSystem.addSubtypeConstraint(typeOfThis.unwrap(), substitutedType, DelegatedPropertyConstraintPosition(atom))
|
||||
}
|
||||
|
||||
private fun ResolvedCallAtom.addConstraintsForGetValueMethod(commonSystem: ConstraintSystemBuilder) {
|
||||
if (expectedType != null) {
|
||||
val unsubstitutedReturnType = candidateDescriptor.returnType?.unwrap() ?: return
|
||||
val substitutedReturnType = substitutor.safeSubstitute(unsubstitutedReturnType)
|
||||
val substitutedReturnType = freshVariablesSubstitutor.safeSubstitute(unsubstitutedReturnType)
|
||||
|
||||
commonSystem.addSubtypeConstraint(substitutedReturnType, expectedType, DelegatedPropertyConstraintPosition(atom))
|
||||
}
|
||||
@@ -71,7 +71,7 @@ class DelegatedPropertyInferenceSession(
|
||||
private fun ResolvedCallAtom.addConstraintsForSetValueMethod(commonSystem: ConstraintSystemBuilder) {
|
||||
if (expectedType != null) {
|
||||
val unsubstitutedParameterType = candidateDescriptor.valueParameters.getOrNull(2)?.type?.unwrap() ?: return
|
||||
val substitutedParameterType = substitutor.safeSubstitute(unsubstitutedParameterType)
|
||||
val substitutedParameterType = freshVariablesSubstitutor.safeSubstitute(unsubstitutedParameterType)
|
||||
|
||||
commonSystem.addSubtypeConstraint(expectedType, substitutedParameterType, DelegatedPropertyConstraintPosition(atom))
|
||||
}
|
||||
|
||||
+4
-3
@@ -712,7 +712,7 @@ class NewResolvedCallImpl<D : CallableDescriptor>(
|
||||
(candidateDescriptor.typeParameters.isNotEmpty() || shouldRunApproximation)) ->
|
||||
// this code is very suspicious. Now it is very useful for BE, because they cannot do nothing with captured types,
|
||||
// but it seems like temporary solution.
|
||||
candidateDescriptor.substitute(resolvedCallAtom.substitutor).substituteAndApproximateTypes(
|
||||
candidateDescriptor.substitute(resolvedCallAtom.freshVariablesSubstitutor).substituteAndApproximateTypes(
|
||||
substitutor ?: FreshVariableNewTypeSubstitutor.Empty, typeApproximator
|
||||
)
|
||||
else ->
|
||||
@@ -720,7 +720,7 @@ class NewResolvedCallImpl<D : CallableDescriptor>(
|
||||
}
|
||||
} as D
|
||||
|
||||
typeArguments = resolvedCallAtom.substitutor.freshVariables.map {
|
||||
typeArguments = resolvedCallAtom.freshVariablesSubstitutor.freshVariables.map {
|
||||
val substituted = (substitutor ?: FreshVariableNewTypeSubstitutor.Empty).safeSubstitute(it.defaultType)
|
||||
typeApproximator
|
||||
.approximateToSuperType(substituted, TypeApproximatorConfiguration.IntegerLiteralsTypesApproximation)
|
||||
@@ -738,7 +738,8 @@ class NewResolvedCallImpl<D : CallableDescriptor>(
|
||||
|
||||
expedtedTypeForSamConvertedArgumentMap = hashMapOf()
|
||||
for ((argument, description) in resolvedCallAtom.argumentsWithConversion) {
|
||||
val typeWithFreshVariables = resolvedCallAtom.substitutor.safeSubstitute(description.convertedTypeByCandidateParameter)
|
||||
val typeWithFreshVariables =
|
||||
resolvedCallAtom.freshVariablesSubstitutor.safeSubstitute(description.convertedTypeByCandidateParameter)
|
||||
val expectedType = substitutor?.safeSubstitute(typeWithFreshVariables) ?: typeWithFreshVariables
|
||||
expedtedTypeForSamConvertedArgumentMap!![argument.psiCallArgument.valueArgument] = expectedType
|
||||
}
|
||||
|
||||
+1
-3
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.addSubtypeConstraintIfCompatible
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.Constraint
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage.Empty.hasContradiction
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ExpectedTypeConstraintPosition
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
@@ -20,7 +19,6 @@ import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContext
|
||||
import org.jetbrains.kotlin.types.model.defaultType
|
||||
import org.jetbrains.kotlin.types.model.isIntegerLiteralTypeConstructor
|
||||
import org.jetbrains.kotlin.types.model.typeConstructor
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
@@ -147,7 +145,7 @@ class KotlinCallCompleter(
|
||||
|
||||
private fun KotlinResolutionCandidate.substitutedReturnType(): UnwrappedType? {
|
||||
val returnType = resolvedCall.candidateDescriptor.returnType?.unwrap() ?: return null
|
||||
return resolvedCall.substitutor.safeSubstitute(returnType)
|
||||
return resolvedCall.freshVariablesSubstitutor.safeSubstitute(returnType)
|
||||
}
|
||||
|
||||
private fun KotlinResolutionCandidate.addExpectedTypeConstraint(
|
||||
|
||||
+5
-5
@@ -125,11 +125,11 @@ internal object NoArguments : ResolutionPart() {
|
||||
internal object CreateFreshVariablesSubstitutor : ResolutionPart() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
if (candidateDescriptor.typeParameters.isEmpty()) {
|
||||
resolvedCall.substitutor = FreshVariableNewTypeSubstitutor.Empty
|
||||
resolvedCall.freshVariablesSubstitutor = FreshVariableNewTypeSubstitutor.Empty
|
||||
return
|
||||
}
|
||||
val toFreshVariables = createToFreshVariableSubstitutorAndAddInitialConstraints(candidateDescriptor, csBuilder)
|
||||
resolvedCall.substitutor = toFreshVariables
|
||||
resolvedCall.freshVariablesSubstitutor = toFreshVariables
|
||||
|
||||
// bad function -- error on declaration side
|
||||
if (csBuilder.hasContradiction) return
|
||||
@@ -232,7 +232,7 @@ internal object PostponedVariablesInitializerResolutionPart : ResolutionPart() {
|
||||
if (!callComponents.statelessCallbacks.isCoroutineCall(argument, parameter)) continue
|
||||
val receiverType = parameter.type.getReceiverTypeFromFunctionType() ?: continue
|
||||
|
||||
for (freshVariable in resolvedCall.substitutor.freshVariables) {
|
||||
for (freshVariable in resolvedCall.freshVariablesSubstitutor.freshVariables) {
|
||||
if (resolvedCall.typeArgumentMappingByOriginal.getTypeArgument(freshVariable.originalTypeParameter) is SimpleTypeArgument)
|
||||
continue
|
||||
|
||||
@@ -284,7 +284,7 @@ private fun KotlinResolutionCandidate.prepareExpectedType(
|
||||
callComponents.languageVersionSettings
|
||||
)
|
||||
val resultType = knownTypeParametersResultingSubstitutor?.substitute(argumentType) ?: argumentType
|
||||
return resolvedCall.substitutor.safeSubstitute(resultType)
|
||||
return resolvedCall.freshVariablesSubstitutor.safeSubstitute(resultType)
|
||||
}
|
||||
|
||||
private fun KotlinResolutionCandidate.getExpectedTypeWithSAMConversion(
|
||||
@@ -414,7 +414,7 @@ internal object ErrorDescriptorResolutionPart : ResolutionPart() {
|
||||
}
|
||||
resolvedCall.typeArgumentMappingByOriginal = TypeArgumentsToParametersMapper.TypeArgumentsMapping.NoExplicitArguments
|
||||
resolvedCall.argumentMappingByOriginal = emptyMap()
|
||||
resolvedCall.substitutor = FreshVariableNewTypeSubstitutor.Empty
|
||||
resolvedCall.freshVariablesSubstitutor = FreshVariableNewTypeSubstitutor.Empty
|
||||
resolvedCall.argumentToCandidateParameter = emptyMap()
|
||||
|
||||
kotlinCall.explicitReceiver?.safeAs<SimpleKotlinCallArgument>()?.let {
|
||||
|
||||
+2
-2
@@ -166,7 +166,7 @@ class KotlinConstraintSystemCompleter(
|
||||
|
||||
fun ResolvedAtom.process(to: LinkedHashSet<TypeConstructor>) {
|
||||
val typeVariables = when (this) {
|
||||
is ResolvedCallAtom -> substitutor.freshVariables
|
||||
is ResolvedCallAtom -> freshVariablesSubstitutor.freshVariables
|
||||
is ResolvedCallableReferenceAtom -> candidate?.freshSubstitutor?.freshVariables.orEmpty()
|
||||
is ResolvedLambdaAtom -> listOfNotNull(typeVariableForLambdaReturnType)
|
||||
else -> emptyList()
|
||||
@@ -247,7 +247,7 @@ class KotlinConstraintSystemCompleter(
|
||||
private fun findResolvedAtomBy(typeVariable: TypeVariableMarker, topLevelAtoms: List<ResolvedAtom>): ResolvedAtom? {
|
||||
fun ResolvedAtom.check(): ResolvedAtom? {
|
||||
val suitableCall = when (this) {
|
||||
is ResolvedCallAtom -> typeVariable in substitutor.freshVariables
|
||||
is ResolvedCallAtom -> typeVariable in freshVariablesSubstitutor.freshVariables
|
||||
is ResolvedCallableReferenceAtom -> candidate?.freshSubstitutor?.freshVariables?.let { typeVariable in it } ?: false
|
||||
is ResolvedLambdaAtom -> typeVariable == typeVariableForLambdaReturnType
|
||||
else -> false
|
||||
|
||||
@@ -63,7 +63,7 @@ abstract class ResolvedCallAtom : ResolvedAtom() {
|
||||
abstract val extensionReceiverArgument: SimpleKotlinCallArgument?
|
||||
abstract val typeArgumentMappingByOriginal: TypeArgumentsToParametersMapper.TypeArgumentsMapping
|
||||
abstract val argumentMappingByOriginal: Map<ValueParameterDescriptor, ResolvedCallArgument>
|
||||
abstract val substitutor: FreshVariableNewTypeSubstitutor
|
||||
abstract val freshVariablesSubstitutor: FreshVariableNewTypeSubstitutor
|
||||
|
||||
abstract val argumentsWithConversion: Map<KotlinCallArgument, SamConversionDescription>
|
||||
}
|
||||
@@ -237,7 +237,7 @@ fun CallResolutionResult.resultCallAtom(): ResolvedCallAtom? =
|
||||
val ResolvedCallAtom.freshReturnType: UnwrappedType?
|
||||
get() {
|
||||
val returnType = candidateDescriptor.returnType ?: return null
|
||||
return substitutor.safeSubstitute(returnType.unwrap())
|
||||
return freshVariablesSubstitutor.safeSubstitute(returnType.unwrap())
|
||||
}
|
||||
|
||||
class PartialCallContainer(val result: PartialCallResolutionResult?) {
|
||||
|
||||
+1
-1
@@ -178,7 +178,7 @@ class MutableResolvedCallAtom(
|
||||
) : ResolvedCallAtom() {
|
||||
override lateinit var typeArgumentMappingByOriginal: TypeArgumentsToParametersMapper.TypeArgumentsMapping
|
||||
override lateinit var argumentMappingByOriginal: Map<ValueParameterDescriptor, ResolvedCallArgument>
|
||||
override lateinit var substitutor: FreshVariableNewTypeSubstitutor
|
||||
override lateinit var freshVariablesSubstitutor: FreshVariableNewTypeSubstitutor
|
||||
lateinit var argumentToCandidateParameter: Map<KotlinCallArgument, ValueParameterDescriptor>
|
||||
private var samAdapterMap: HashMap<KotlinCallArgument, SamConversionDescription>? = null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user