K1: cleanup new inference constructor resolve in CallResolverUtil
This commit is contained in:
committed by
teamcity
parent
e20efc1398
commit
ec055eb418
@@ -52,6 +52,7 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||||
import org.jetbrains.kotlin.util.buildNotFixedVariablesToPossibleResultType
|
import org.jetbrains.kotlin.util.buildNotFixedVariablesToPossibleResultType
|
||||||
import org.jetbrains.kotlin.utils.SmartList
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.runIf
|
||||||
|
|
||||||
enum class ResolveArgumentsMode {
|
enum class ResolveArgumentsMode {
|
||||||
RESOLVE_FUNCTION_ARGUMENTS,
|
RESOLVE_FUNCTION_ARGUMENTS,
|
||||||
@@ -283,29 +284,30 @@ fun isArrayOrArrayLiteral(argument: ValueArgument, trace: BindingTrace): Boolean
|
|||||||
return KotlinBuiltIns.isArrayOrPrimitiveArray(type)
|
return KotlinBuiltIns.isArrayOrPrimitiveArray(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun computeConstructorDescriptorsToResolveAndReceiver(
|
private fun computeConstructorDispatchReceiver(
|
||||||
constructors: Collection<ConstructorDescriptor>,
|
|
||||||
containingClass: ClassDescriptor,
|
containingClass: ClassDescriptor,
|
||||||
scope: LexicalScope,
|
scope: LexicalScope,
|
||||||
substitutor: TypeSubstitutor?,
|
substitutor: TypeSubstitutor?
|
||||||
syntheticScopes: SyntheticScopes
|
): ReceiverValue? {
|
||||||
): Pair<Collection<ConstructorDescriptor>, ReceiverValue?>? {
|
return runIf(containingClass.isInner) {
|
||||||
val dispatchReceiver: ReceiverValue? = if (containingClass.isInner) {
|
|
||||||
val outerClassType = (containingClass.containingDeclaration as? ClassDescriptor)?.defaultType ?: return null
|
val outerClassType = (containingClass.containingDeclaration as? ClassDescriptor)?.defaultType ?: return null
|
||||||
val substitutedOuterClassType = substitutor?.substitute(outerClassType, Variance.INVARIANT) ?: outerClassType
|
val substitutedOuterClassType = substitutor?.substitute(outerClassType, Variance.INVARIANT) ?: outerClassType
|
||||||
val receiver = scope.getImplicitReceiversHierarchy().firstOrNull {
|
scope.getImplicitReceiversHierarchy().firstOrNull {
|
||||||
KotlinTypeChecker.DEFAULT.isSubtypeOf(it.type, substitutedOuterClassType)
|
KotlinTypeChecker.DEFAULT.isSubtypeOf(it.type, substitutedOuterClassType)
|
||||||
} ?: return null
|
}?.value
|
||||||
|
|
||||||
receiver.value
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val syntheticConstructors = constructors.flatMap { syntheticScopes.collectSyntheticConstructors(it) }
|
private fun computeConstructorDescriptorsToResolve(
|
||||||
|
containingClass: ClassDescriptor,
|
||||||
return constructors + syntheticConstructors to dispatchReceiver
|
typeAliasDescriptorIfAny: TypeAliasDescriptor?,
|
||||||
|
syntheticScopes: SyntheticScopes
|
||||||
|
): Collection<ConstructorDescriptor> {
|
||||||
|
val simpleConstructors =
|
||||||
|
typeAliasDescriptorIfAny?.constructors?.mapNotNull(TypeAliasConstructorDescriptor::withDispatchReceiver)
|
||||||
|
?: containingClass.constructors
|
||||||
|
val syntheticConstructors = simpleConstructors.flatMap { syntheticScopes.collectSyntheticConstructors(it) }
|
||||||
|
return simpleConstructors + syntheticConstructors
|
||||||
}
|
}
|
||||||
|
|
||||||
fun resolveConstructorCallWithGivenDescriptors(
|
fun resolveConstructorCallWithGivenDescriptors(
|
||||||
@@ -320,25 +322,20 @@ fun resolveConstructorCallWithGivenDescriptors(
|
|||||||
|
|
||||||
@Suppress("NAME_SHADOWING")
|
@Suppress("NAME_SHADOWING")
|
||||||
val constructorType = constructorType.unwrap()
|
val constructorType = constructorType.unwrap()
|
||||||
val knownSubstitutor = if (useKnownTypeSubstitutor) {
|
val constructorTypeAbbreviation = (constructorType as? AbbreviatedType)?.abbreviation
|
||||||
TypeSubstitutor.create((constructorType as? AbbreviatedType)?.abbreviation ?: constructorType)
|
val knownSubstitutor = runIf(useKnownTypeSubstitutor) {
|
||||||
} else null
|
TypeSubstitutor.create(constructorTypeAbbreviation ?: constructorType)
|
||||||
val typeAliasDescriptor = if (constructorType is AbbreviatedType) {
|
}
|
||||||
constructorType.abbreviation.constructor.declarationDescriptor as? TypeAliasDescriptor
|
val typeAliasDescriptor = constructorTypeAbbreviation?.constructor?.declarationDescriptor as? TypeAliasDescriptor
|
||||||
} else null
|
|
||||||
|
|
||||||
val (constructors, receiver) = computeConstructorDescriptorsToResolveAndReceiver(
|
val receiver = computeConstructorDispatchReceiver(containingClass, context.scope, knownSubstitutor)
|
||||||
constructors = typeAliasDescriptor?.constructors?.mapNotNull(TypeAliasConstructorDescriptor::withDispatchReceiver)
|
val allConstructors = runIf(!containingClass.isInner || receiver != null) {
|
||||||
?: containingClass.constructors,
|
computeConstructorDescriptorsToResolve(containingClass, typeAliasDescriptor, syntheticScopes)
|
||||||
containingClass,
|
}.orEmpty()
|
||||||
context.scope,
|
|
||||||
knownSubstitutor,
|
|
||||||
syntheticScopes
|
|
||||||
) ?: (emptyList<ConstructorDescriptor>() to null)
|
|
||||||
|
|
||||||
val resolutionResults = PSICallResolver.runResolutionAndInferenceForGivenDescriptors<ConstructorDescriptor>(
|
val resolutionResults = PSICallResolver.runResolutionAndInferenceForGivenDescriptors<ConstructorDescriptor>(
|
||||||
context,
|
context,
|
||||||
constructors,
|
allConstructors,
|
||||||
tracingStrategy,
|
tracingStrategy,
|
||||||
KotlinCallKind.FUNCTION,
|
KotlinCallKind.FUNCTION,
|
||||||
knownSubstitutor,
|
knownSubstitutor,
|
||||||
|
|||||||
Reference in New Issue
Block a user