diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyInferenceSession.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyInferenceSession.kt index 03603d42465..32fe600a1bb 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyInferenceSession.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DelegatedPropertyInferenceSession.kt @@ -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)) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt index a1c9a76ba65..ada5902dc93 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt @@ -712,7 +712,7 @@ class NewResolvedCallImpl( (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( } } 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( 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 } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt index 5b55d05ee71..8e870cce568 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt @@ -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( diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index 507e91122b5..9aa870e2b46 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -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()?.let { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt index a9b0d31d7f3..0417ce56d6d 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/KotlinConstraintSystemCompleter.kt @@ -166,7 +166,7 @@ class KotlinConstraintSystemCompleter( fun ResolvedAtom.process(to: LinkedHashSet) { 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? { 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 diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt index de93cdb0afb..7fca223d5f3 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionAtoms.kt @@ -63,7 +63,7 @@ abstract class ResolvedCallAtom : ResolvedAtom() { abstract val extensionReceiverArgument: SimpleKotlinCallArgument? abstract val typeArgumentMappingByOriginal: TypeArgumentsToParametersMapper.TypeArgumentsMapping abstract val argumentMappingByOriginal: Map - abstract val substitutor: FreshVariableNewTypeSubstitutor + abstract val freshVariablesSubstitutor: FreshVariableNewTypeSubstitutor abstract val argumentsWithConversion: Map } @@ -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?) { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionCandidate.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionCandidate.kt index 4672868c682..3277453ff96 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionCandidate.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/ResolutionCandidate.kt @@ -178,7 +178,7 @@ class MutableResolvedCallAtom( ) : ResolvedCallAtom() { override lateinit var typeArgumentMappingByOriginal: TypeArgumentsToParametersMapper.TypeArgumentsMapping override lateinit var argumentMappingByOriginal: Map - override lateinit var substitutor: FreshVariableNewTypeSubstitutor + override lateinit var freshVariablesSubstitutor: FreshVariableNewTypeSubstitutor lateinit var argumentToCandidateParameter: Map private var samAdapterMap: HashMap? = null