Introduce frontend independent constraint positions
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
|||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.impl.FirTypePlaceholderProjection
|
import org.jetbrains.kotlin.fir.types.impl.FirTypePlaceholderProjection
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.FirDeclaredUpperBoundConstraintPosition
|
import org.jetbrains.kotlin.fir.resolve.inference.model.FirDeclaredUpperBoundConstraintPosition
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
|
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
|
||||||
|
|
||||||
internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() {
|
internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() {
|
||||||
|
|||||||
+1
-1
@@ -190,7 +190,7 @@ class FirBuilderInferenceSession(
|
|||||||
for ((variableConstructor, type) in storage.fixedTypeVariables) {
|
for ((variableConstructor, type) in storage.fixedTypeVariables) {
|
||||||
val typeVariable = storage.allTypeVariables.getValue(variableConstructor)
|
val typeVariable = storage.allTypeVariables.getValue(variableConstructor)
|
||||||
commonSystem.registerVariable(typeVariable)
|
commonSystem.registerVariable(typeVariable)
|
||||||
commonSystem.addEqualityConstraint((typeVariable as ConeTypeVariable).defaultType, type, CoroutinePosition())
|
commonSystem.addEqualityConstraint((typeVariable as ConeTypeVariable).defaultType, type, CoroutinePosition)
|
||||||
introducedConstraint = true
|
introducedConstraint = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -142,7 +142,7 @@ class PostponedArgumentsAnalyzer(
|
|||||||
val variable = variableWithConstraints.typeVariable as ConeTypeVariable
|
val variable = variableWithConstraints.typeVariable as ConeTypeVariable
|
||||||
|
|
||||||
c.getBuilder().unmarkPostponedVariable(variable)
|
c.getBuilder().unmarkPostponedVariable(variable)
|
||||||
c.getBuilder().addEqualityConstraint(variable.defaultType, resultType, CoroutinePosition())
|
c.getBuilder().addEqualityConstraint(variable.defaultType, resultType, CoroutinePosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.fir.resolve.inference.model
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.inference.model.DeclaredUpperBoundConstraintPosition
|
||||||
|
|
||||||
|
class FirDeclaredUpperBoundConstraintPosition : DeclaredUpperBoundConstraintPosition<Nothing?>(null)
|
||||||
+4
-4
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
|||||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.DelegatedPropertyConstraintPosition
|
import org.jetbrains.kotlin.resolve.calls.inference.model.DelegatedPropertyConstraintPositionImpl
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.ManyCandidatesResolver
|
import org.jetbrains.kotlin.resolve.calls.tower.ManyCandidatesResolver
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.PSICallResolver
|
import org.jetbrains.kotlin.resolve.calls.tower.PSICallResolver
|
||||||
@@ -54,7 +54,7 @@ class DelegatedPropertyInferenceSession(
|
|||||||
|
|
||||||
val valueParameterForThis = descriptor.valueParameters.getOrNull(0) ?: return
|
val valueParameterForThis = descriptor.valueParameters.getOrNull(0) ?: return
|
||||||
val substitutedType = freshVariablesSubstitutor.safeSubstitute(valueParameterForThis.type.unwrap())
|
val substitutedType = freshVariablesSubstitutor.safeSubstitute(valueParameterForThis.type.unwrap())
|
||||||
commonSystem.addSubtypeConstraint(typeOfThis.unwrap(), substitutedType, DelegatedPropertyConstraintPosition(atom))
|
commonSystem.addSubtypeConstraint(typeOfThis.unwrap(), substitutedType, DelegatedPropertyConstraintPositionImpl(atom))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ResolvedCallAtom.addConstraintsForGetValueMethod(commonSystem: ConstraintSystemBuilder) {
|
private fun ResolvedCallAtom.addConstraintsForGetValueMethod(commonSystem: ConstraintSystemBuilder) {
|
||||||
@@ -62,7 +62,7 @@ class DelegatedPropertyInferenceSession(
|
|||||||
val unsubstitutedReturnType = candidateDescriptor.returnType?.unwrap() ?: return
|
val unsubstitutedReturnType = candidateDescriptor.returnType?.unwrap() ?: return
|
||||||
val substitutedReturnType = freshVariablesSubstitutor.safeSubstitute(unsubstitutedReturnType)
|
val substitutedReturnType = freshVariablesSubstitutor.safeSubstitute(unsubstitutedReturnType)
|
||||||
|
|
||||||
commonSystem.addSubtypeConstraint(substitutedReturnType, expectedType, DelegatedPropertyConstraintPosition(atom))
|
commonSystem.addSubtypeConstraint(substitutedReturnType, expectedType, DelegatedPropertyConstraintPositionImpl(atom))
|
||||||
}
|
}
|
||||||
|
|
||||||
addConstraintForThis(candidateDescriptor, commonSystem)
|
addConstraintForThis(candidateDescriptor, commonSystem)
|
||||||
@@ -73,7 +73,7 @@ class DelegatedPropertyInferenceSession(
|
|||||||
val unsubstitutedParameterType = candidateDescriptor.valueParameters.getOrNull(2)?.type?.unwrap() ?: return
|
val unsubstitutedParameterType = candidateDescriptor.valueParameters.getOrNull(2)?.type?.unwrap() ?: return
|
||||||
val substitutedParameterType = freshVariablesSubstitutor.safeSubstitute(unsubstitutedParameterType)
|
val substitutedParameterType = freshVariablesSubstitutor.safeSubstitute(unsubstitutedParameterType)
|
||||||
|
|
||||||
commonSystem.addSubtypeConstraint(expectedType, substitutedParameterType, DelegatedPropertyConstraintPosition(atom))
|
commonSystem.addSubtypeConstraint(expectedType, substitutedParameterType, DelegatedPropertyConstraintPositionImpl(atom))
|
||||||
}
|
}
|
||||||
|
|
||||||
addConstraintForThis(candidateDescriptor, commonSystem)
|
addConstraintForThis(candidateDescriptor, commonSystem)
|
||||||
|
|||||||
+11
-11
@@ -347,10 +347,10 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
val position = constraintError.position.from
|
val position = constraintError.position.from
|
||||||
val argument =
|
val argument =
|
||||||
when (position) {
|
when (position) {
|
||||||
is ArgumentConstraintPosition -> position.argument
|
is ArgumentConstraintPositionImpl -> position.argument
|
||||||
is ReceiverConstraintPosition -> position.argument
|
is ReceiverConstraintPositionImpl -> position.argument
|
||||||
is LHSArgumentConstraintPosition -> position.argument
|
is LHSArgumentConstraintPositionImpl -> position.argument
|
||||||
is LambdaArgumentConstraintPosition -> position.lambda.atom
|
is LambdaArgumentConstraintPositionImpl -> position.lambda.atom
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
argument?.let {
|
argument?.let {
|
||||||
@@ -385,7 +385,7 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
(position as? ExpectedTypeConstraintPosition)?.let {
|
(position as? ExpectedTypeConstraintPositionImpl)?.let {
|
||||||
val call = it.topLevelCall.psiKotlinCall.psiCall.callElement.safeAs<KtExpression>()
|
val call = it.topLevelCall.psiKotlinCall.psiCall.callElement.safeAs<KtExpression>()
|
||||||
val inferredType =
|
val inferredType =
|
||||||
if (!constraintError.lowerKotlinType.isNullableNothing()) constraintError.lowerKotlinType
|
if (!constraintError.lowerKotlinType.isNullableNothing()) constraintError.lowerKotlinType
|
||||||
@@ -401,7 +401,7 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(position as? ExplicitTypeParameterConstraintPosition)?.let {
|
(position as? ExplicitTypeParameterConstraintPositionImpl)?.let {
|
||||||
val typeArgumentReference = (it.typeArgument as SimpleTypeArgumentImpl).typeReference
|
val typeArgumentReference = (it.typeArgument as SimpleTypeArgumentImpl).typeReference
|
||||||
trace.report(
|
trace.report(
|
||||||
UPPER_BOUND_VIOLATED.on(
|
UPPER_BOUND_VIOLATED.on(
|
||||||
@@ -412,9 +412,9 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
(position as? FixVariableConstraintPosition)?.let {
|
(position as? FixVariableConstraintPositionImpl)?.let {
|
||||||
val morePreciseDiagnosticExists = allDiagnostics.any { other ->
|
val morePreciseDiagnosticExists = allDiagnostics.any { other ->
|
||||||
other is NewConstraintError && other.position.from !is FixVariableConstraintPosition
|
other is NewConstraintError && other.position.from !is FixVariableConstraintPositionImpl
|
||||||
}
|
}
|
||||||
if (morePreciseDiagnosticExists) return
|
if (morePreciseDiagnosticExists) return
|
||||||
|
|
||||||
@@ -435,8 +435,8 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
val capturedError = diagnostic as CapturedTypeFromSubtyping
|
val capturedError = diagnostic as CapturedTypeFromSubtyping
|
||||||
val position = capturedError.position
|
val position = capturedError.position
|
||||||
val argumentPosition =
|
val argumentPosition =
|
||||||
position.safeAs<ArgumentConstraintPosition>()
|
position.safeAs<ArgumentConstraintPositionImpl>()
|
||||||
?: position.safeAs<IncorporationConstraintPosition>()?.from.safeAs<ArgumentConstraintPosition>()
|
?: position.safeAs<IncorporationConstraintPosition>()?.from.safeAs<ArgumentConstraintPositionImpl>()
|
||||||
|
|
||||||
argumentPosition?.let {
|
argumentPosition?.let {
|
||||||
val expression = it.argument.psiExpression ?: return
|
val expression = it.argument.psiExpression ?: return
|
||||||
@@ -450,7 +450,7 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
}
|
}
|
||||||
|
|
||||||
NotEnoughInformationForTypeParameter::class.java -> {
|
NotEnoughInformationForTypeParameter::class.java -> {
|
||||||
val error = diagnostic as NotEnoughInformationForTypeParameter
|
val error = diagnostic as NotEnoughInformationForTypeParameterImpl
|
||||||
if (allDiagnostics.any {
|
if (allDiagnostics.any {
|
||||||
(it is ConstrainingTypeIsError && it.typeVariable == error.typeVariable)
|
(it is ConstrainingTypeIsError && it.typeVariable == error.typeVariable)
|
||||||
|| it is NewConstraintError || it is WrongCountOfTypeArguments
|
|| it is NewConstraintError || it is WrongCountOfTypeArguments
|
||||||
|
|||||||
+1
-1
@@ -248,7 +248,7 @@ class CoroutineInferenceSession(
|
|||||||
for ((variableConstructor, type) in storage.fixedTypeVariables) {
|
for ((variableConstructor, type) in storage.fixedTypeVariables) {
|
||||||
val typeVariable = storage.allTypeVariables.getValue(variableConstructor)
|
val typeVariable = storage.allTypeVariables.getValue(variableConstructor)
|
||||||
commonSystem.registerVariable(typeVariable)
|
commonSystem.registerVariable(typeVariable)
|
||||||
commonSystem.addEqualityConstraint((typeVariable as NewTypeVariable).defaultType, type, CoroutinePosition())
|
commonSystem.addEqualityConstraint((typeVariable as NewTypeVariable).defaultType, type, CoroutinePosition)
|
||||||
introducedConstraint = true
|
introducedConstraint = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -909,7 +909,7 @@ class NewResolvedCallImpl<D : CallableDescriptor>(
|
|||||||
is CapturedTypeFromSubtyping -> it.position.originalPosition()
|
is CapturedTypeFromSubtyping -> it.position.originalPosition()
|
||||||
is ConstrainingTypeIsError -> it.position.originalPosition()
|
is ConstrainingTypeIsError -> it.position.originalPosition()
|
||||||
else -> null
|
else -> null
|
||||||
} as? ArgumentConstraintPosition ?: return@forEach
|
} as? ArgumentConstraintPositionImpl ?: return@forEach
|
||||||
|
|
||||||
val argument = position.argument.safeAs<PSIKotlinCallArgument>()?.valueArgument ?: return@forEach
|
val argument = position.argument.safeAs<PSIKotlinCallArgument>()?.valueArgument ?: return@forEach
|
||||||
result += argument to it
|
result += argument to it
|
||||||
|
|||||||
+3
-3
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|||||||
import org.jetbrains.kotlin.resolve.calls.components.CreateFreshVariablesSubstitutor.createToFreshVariableSubstitutorAndAddInitialConstraints
|
import org.jetbrains.kotlin.resolve.calls.components.CreateFreshVariablesSubstitutor.createToFreshVariableSubstitutorAndAddInitialConstraints
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
|
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ArgumentConstraintPosition
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ArgumentConstraintPositionImpl
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.DISPATCH_RECEIVER
|
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.DISPATCH_RECEIVER
|
||||||
@@ -140,7 +140,7 @@ fun ConstraintSystemOperation.checkCallableReference(
|
|||||||
expectedType: UnwrappedType?,
|
expectedType: UnwrappedType?,
|
||||||
ownerDescriptor: DeclarationDescriptor
|
ownerDescriptor: DeclarationDescriptor
|
||||||
): Pair<FreshVariableNewTypeSubstitutor, KotlinCallDiagnostic?> {
|
): Pair<FreshVariableNewTypeSubstitutor, KotlinCallDiagnostic?> {
|
||||||
val position = ArgumentConstraintPosition(argument)
|
val position = ArgumentConstraintPositionImpl(argument)
|
||||||
|
|
||||||
val toFreshSubstitutor = createToFreshVariableSubstitutorAndAddInitialConstraints(candidateDescriptor, this)
|
val toFreshSubstitutor = createToFreshVariableSubstitutorAndAddInitialConstraints(candidateDescriptor, this)
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ private fun ConstraintSystemOperation.addReceiverConstraint(
|
|||||||
toFreshSubstitutor: FreshVariableNewTypeSubstitutor,
|
toFreshSubstitutor: FreshVariableNewTypeSubstitutor,
|
||||||
receiverArgument: CallableReceiver?,
|
receiverArgument: CallableReceiver?,
|
||||||
receiverParameter: ReceiverParameterDescriptor?,
|
receiverParameter: ReceiverParameterDescriptor?,
|
||||||
position: ArgumentConstraintPosition
|
position: ArgumentConstraintPositionImpl
|
||||||
) {
|
) {
|
||||||
if (receiverArgument == null || receiverParameter == null) {
|
if (receiverArgument == null || receiverParameter == null) {
|
||||||
assert(receiverArgument == null) { "Receiver argument should be null if parameter is: $receiverArgument" }
|
assert(receiverArgument == null) { "Receiver argument should be null if parameter is: $receiverArgument" }
|
||||||
|
|||||||
+4
-4
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintS
|
|||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode
|
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.TrivialConstraintTypeInferenceOracle
|
import org.jetbrains.kotlin.resolve.calls.inference.components.TrivialConstraintTypeInferenceOracle
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage.Empty.hasContradiction
|
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.inference.model.ExpectedTypeConstraintPositionImpl
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.forceResolution
|
import org.jetbrains.kotlin.resolve.calls.tower.forceResolution
|
||||||
import org.jetbrains.kotlin.types.ErrorUtils
|
import org.jetbrains.kotlin.types.ErrorUtils
|
||||||
@@ -286,11 +286,11 @@ class KotlinCallCompleter(
|
|||||||
|
|
||||||
expectedType === TypeUtils.UNIT_EXPECTED_TYPE ->
|
expectedType === TypeUtils.UNIT_EXPECTED_TYPE ->
|
||||||
csBuilder.addEqualityConstraintIfCompatible(
|
csBuilder.addEqualityConstraintIfCompatible(
|
||||||
returnType, csBuilder.builtIns.unitType, ExpectedTypeConstraintPosition(resolvedCall.atom)
|
returnType, csBuilder.builtIns.unitType, ExpectedTypeConstraintPositionImpl(resolvedCall.atom)
|
||||||
)
|
)
|
||||||
|
|
||||||
else ->
|
else ->
|
||||||
csBuilder.addSubtypeConstraint(returnType, expectedType, ExpectedTypeConstraintPosition(resolvedCall.atom))
|
csBuilder.addSubtypeConstraint(returnType, expectedType, ExpectedTypeConstraintPositionImpl(resolvedCall.atom))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,7 +301,7 @@ class KotlinCallCompleter(
|
|||||||
if (!callComponents.languageVersionSettings.supportsFeature(LanguageFeature.ExpectedTypeFromCast)) return
|
if (!callComponents.languageVersionSettings.supportsFeature(LanguageFeature.ExpectedTypeFromCast)) return
|
||||||
if (returnType == null) return
|
if (returnType == null) return
|
||||||
val expectedType = resolutionCallbacks.getExpectedTypeFromAsExpressionAndRecordItInTrace(resolvedCall) ?: return
|
val expectedType = resolutionCallbacks.getExpectedTypeFromAsExpressionAndRecordItInTrace(resolvedCall) ?: return
|
||||||
csBuilder.addSubtypeConstraint(returnType, expectedType, ExpectedTypeConstraintPosition(resolvedCall.atom))
|
csBuilder.addSubtypeConstraint(returnType, expectedType, ExpectedTypeConstraintPositionImpl(resolvedCall.atom))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinResolutionCandidate.asCallResolutionResult(
|
fun KotlinResolutionCandidate.asCallResolutionResult(
|
||||||
|
|||||||
+7
-4
@@ -22,7 +22,10 @@ import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
|||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
|
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||||
|
import org.jetbrains.kotlin.types.ErrorUtils
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.UnwrappedType
|
||||||
import org.jetbrains.kotlin.types.checker.convertVariance
|
import org.jetbrains.kotlin.types.checker.convertVariance
|
||||||
import org.jetbrains.kotlin.types.model.TypeVariance
|
import org.jetbrains.kotlin.types.model.TypeVariance
|
||||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||||
@@ -69,7 +72,7 @@ private fun preprocessLambdaArgument(
|
|||||||
|
|
||||||
if (expectedTypeVariableWithConstraints != null) {
|
if (expectedTypeVariableWithConstraints != null) {
|
||||||
val explicitTypeArgument = expectedTypeVariableWithConstraints.constraints.find {
|
val explicitTypeArgument = expectedTypeVariableWithConstraints.constraints.find {
|
||||||
it.kind == ConstraintKind.EQUALITY && it.position.from is ExplicitTypeParameterConstraintPosition
|
it.kind == ConstraintKind.EQUALITY && it.position.from is ExplicitTypeParameterConstraintPosition<*>
|
||||||
}?.type as? KotlinType
|
}?.type as? KotlinType
|
||||||
|
|
||||||
if (explicitTypeArgument == null || explicitTypeArgument.arguments.isNotEmpty()) {
|
if (explicitTypeArgument == null || explicitTypeArgument.arguments.isNotEmpty()) {
|
||||||
@@ -86,7 +89,7 @@ private fun preprocessLambdaArgument(
|
|||||||
csBuilder.builtIns, Annotations.EMPTY, resolvedArgument.receiver,
|
csBuilder.builtIns, Annotations.EMPTY, resolvedArgument.receiver,
|
||||||
resolvedArgument.parameters, null, resolvedArgument.returnType, resolvedArgument.isSuspend
|
resolvedArgument.parameters, null, resolvedArgument.returnType, resolvedArgument.isSuspend
|
||||||
)
|
)
|
||||||
csBuilder.addSubtypeConstraint(lambdaType, expectedType, ArgumentConstraintPosition(argument))
|
csBuilder.addSubtypeConstraint(lambdaType, expectedType, ArgumentConstraintPositionImpl(argument))
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolvedArgument
|
return resolvedArgument
|
||||||
@@ -278,7 +281,7 @@ private fun ConstraintSystemBuilder.addConstraintFromLHS(
|
|||||||
val lhsType = lhsResult.unboundDetailedReceiver.stableType
|
val lhsType = lhsResult.unboundDetailedReceiver.stableType
|
||||||
val expectedTypeProjectionForLHS = expectedType.arguments.first()
|
val expectedTypeProjectionForLHS = expectedType.arguments.first()
|
||||||
val expectedTypeForLHS = expectedTypeProjectionForLHS.type
|
val expectedTypeForLHS = expectedTypeProjectionForLHS.type
|
||||||
val constraintPosition = LHSArgumentConstraintPosition(argument, lhsResult.qualifier ?: lhsResult.unboundDetailedReceiver)
|
val constraintPosition = LHSArgumentConstraintPositionImpl(argument, lhsResult.qualifier ?: lhsResult.unboundDetailedReceiver)
|
||||||
val expectedTypeVariance = expectedTypeProjectionForLHS.projectionKind.convertVariance()
|
val expectedTypeVariance = expectedTypeProjectionForLHS.projectionKind.convertVariance()
|
||||||
val effectiveVariance = AbstractTypeChecker.effectiveVariance(
|
val effectiveVariance = AbstractTypeChecker.effectiveVariance(
|
||||||
expectedType.constructor.parameters.first().variance.convertVariance(),
|
expectedType.constructor.parameters.first().variance.convertVariance(),
|
||||||
|
|||||||
+3
-4
@@ -14,10 +14,9 @@ import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations
|
|||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.addSubsystemFromArgument
|
import org.jetbrains.kotlin.resolve.calls.inference.addSubsystemFromArgument
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutorByConstructorMap
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.CoroutinePosition
|
import org.jetbrains.kotlin.resolve.calls.inference.model.CoroutinePosition
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.LambdaArgumentConstraintPosition
|
import org.jetbrains.kotlin.resolve.calls.inference.model.LambdaArgumentConstraintPositionImpl
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.UnwrappedType
|
import org.jetbrains.kotlin.types.UnwrappedType
|
||||||
@@ -191,7 +190,7 @@ class PostponedArgumentsAnalyzer(
|
|||||||
if (!returnArgumentsInfo.returnArgumentsExist) {
|
if (!returnArgumentsInfo.returnArgumentsExist) {
|
||||||
val unitType = lambda.returnType.builtIns.unitType
|
val unitType = lambda.returnType.builtIns.unitType
|
||||||
val lambdaReturnType = lambda.returnType.let(substitute)
|
val lambdaReturnType = lambda.returnType.let(substitute)
|
||||||
c.getBuilder().addSubtypeConstraint(unitType, lambdaReturnType, LambdaArgumentConstraintPosition(lambda))
|
c.getBuilder().addSubtypeConstraint(unitType, lambdaReturnType, LambdaArgumentConstraintPositionImpl(lambda))
|
||||||
}
|
}
|
||||||
|
|
||||||
lambda.setAnalyzedResults(returnArgumentsInfo, subResolvedKtPrimitives)
|
lambda.setAnalyzedResults(returnArgumentsInfo, subResolvedKtPrimitives)
|
||||||
@@ -215,7 +214,7 @@ class PostponedArgumentsAnalyzer(
|
|||||||
val variable = variableWithConstraints.typeVariable
|
val variable = variableWithConstraints.typeVariable
|
||||||
|
|
||||||
c.getBuilder().unmarkPostponedVariable(variable)
|
c.getBuilder().unmarkPostponedVariable(variable)
|
||||||
c.getBuilder().addEqualityConstraint(variable.defaultType(c), resultType, CoroutinePosition())
|
c.getBuilder().addEqualityConstraint(variable.defaultType(c), resultType, CoroutinePosition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -142,7 +142,7 @@ internal object CreateFreshVariablesSubstitutor : ResolutionPart() {
|
|||||||
csBuilder.addEqualityConstraint(
|
csBuilder.addEqualityConstraint(
|
||||||
freshVariable.defaultType,
|
freshVariable.defaultType,
|
||||||
getTypePreservingFlexibilityWrtTypeVariable(knownTypeArgument.unwrap(), freshVariable),
|
getTypePreservingFlexibilityWrtTypeVariable(knownTypeArgument.unwrap(), freshVariable),
|
||||||
KnownTypeParameterConstraintPosition(knownTypeArgument)
|
KnownTypeParameterConstraintPositionImpl(knownTypeArgument)
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -153,7 +153,7 @@ internal object CreateFreshVariablesSubstitutor : ResolutionPart() {
|
|||||||
csBuilder.addEqualityConstraint(
|
csBuilder.addEqualityConstraint(
|
||||||
freshVariable.defaultType,
|
freshVariable.defaultType,
|
||||||
getTypePreservingFlexibilityWrtTypeVariable(typeArgument.type, freshVariable),
|
getTypePreservingFlexibilityWrtTypeVariable(typeArgument.type, freshVariable),
|
||||||
ExplicitTypeParameterConstraintPosition(typeArgument)
|
ExplicitTypeParameterConstraintPositionImpl(typeArgument)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
assert(typeArgument == TypeArgumentPlaceholder) {
|
assert(typeArgument == TypeArgumentPlaceholder) {
|
||||||
@@ -192,7 +192,7 @@ internal object CreateFreshVariablesSubstitutor : ResolutionPart() {
|
|||||||
|
|
||||||
fun TypeVariableFromCallableDescriptor.addSubtypeConstraint(
|
fun TypeVariableFromCallableDescriptor.addSubtypeConstraint(
|
||||||
upperBound: KotlinType,
|
upperBound: KotlinType,
|
||||||
position: DeclaredUpperBoundConstraintPosition
|
position: DeclaredUpperBoundConstraintPositionImpl
|
||||||
) {
|
) {
|
||||||
csBuilder.addSubtypeConstraint(defaultType, toFreshVariables.safeSubstitute(upperBound.unwrap()), position)
|
csBuilder.addSubtypeConstraint(defaultType, toFreshVariables.safeSubstitute(upperBound.unwrap()), position)
|
||||||
}
|
}
|
||||||
@@ -363,7 +363,7 @@ internal object CollectionTypeVariableUsagesInfo : ResolutionPart() {
|
|||||||
val dependentTypeParameters = getBuilder().currentStorage().notFixedTypeVariables.asSequence()
|
val dependentTypeParameters = getBuilder().currentStorage().notFixedTypeVariables.asSequence()
|
||||||
.flatMap { (typeConstructor, constraints) ->
|
.flatMap { (typeConstructor, constraints) ->
|
||||||
val upperBounds = constraints.constraints.filter {
|
val upperBounds = constraints.constraints.filter {
|
||||||
it.position.from is DeclaredUpperBoundConstraintPosition && it.kind == ConstraintKind.UPPER
|
it.position.from is DeclaredUpperBoundConstraintPositionImpl && it.kind == ConstraintKind.UPPER
|
||||||
}
|
}
|
||||||
|
|
||||||
upperBounds.mapNotNull { constraint ->
|
upperBounds.mapNotNull { constraint ->
|
||||||
@@ -403,7 +403,7 @@ internal object CollectionTypeVariableUsagesInfo : ResolutionPart() {
|
|||||||
|
|
||||||
private fun NewConstraintSystem.getDependingOnTypeParameter(variable: TypeConstructor) =
|
private fun NewConstraintSystem.getDependingOnTypeParameter(variable: TypeConstructor) =
|
||||||
getBuilder().currentStorage().notFixedTypeVariables[variable]?.constraints?.mapNotNull {
|
getBuilder().currentStorage().notFixedTypeVariables[variable]?.constraints?.mapNotNull {
|
||||||
if (it.position.from is DeclaredUpperBoundConstraintPosition && it.kind == ConstraintKind.UPPER) {
|
if (it.position.from is DeclaredUpperBoundConstraintPositionImpl && it.kind == ConstraintKind.UPPER) {
|
||||||
it.type.typeConstructor(asConstraintSystemCompleterContext())
|
it.type.typeConstructor(asConstraintSystemCompleterContext())
|
||||||
} else null
|
} else null
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
@@ -561,7 +561,7 @@ private fun KotlinResolutionCandidate.shouldRunConversionForConstants(expectedTy
|
|||||||
val variableWithConstraints = csBuilder.currentStorage().notFixedTypeVariables[expectedType.constructor] ?: return false
|
val variableWithConstraints = csBuilder.currentStorage().notFixedTypeVariables[expectedType.constructor] ?: return false
|
||||||
return variableWithConstraints.constraints.any {
|
return variableWithConstraints.constraints.any {
|
||||||
it.kind == ConstraintKind.EQUALITY &&
|
it.kind == ConstraintKind.EQUALITY &&
|
||||||
it.position.from is ExplicitTypeParameterConstraintPosition &&
|
it.position.from is ExplicitTypeParameterConstraintPositionImpl &&
|
||||||
UnsignedTypes.isUnsignedType(it.type as UnwrappedType)
|
UnsignedTypes.isUnsignedType(it.type as UnwrappedType)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -728,4 +728,4 @@ internal object ErrorDescriptorResolutionPart : ResolutionPart() {
|
|||||||
resolveKotlinArgument(it, null, ReceiverInfo.notReceiver)
|
resolveKotlinArgument(it, null, ReceiverInfo.notReceiver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -21,9 +21,9 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
|||||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.addSubtypeConstraintIfCompatible
|
import org.jetbrains.kotlin.resolve.calls.inference.addSubtypeConstraintIfCompatible
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
|
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ArgumentConstraintPosition
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ArgumentConstraintPositionImpl
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintPosition
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintPosition
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ReceiverConstraintPosition
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ReceiverConstraintPositionImpl
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.checker.captureFromExpression
|
import org.jetbrains.kotlin.types.checker.captureFromExpression
|
||||||
@@ -93,7 +93,7 @@ private fun checkExpressionArgument(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
val position = if (isReceiver) ReceiverConstraintPosition(expressionArgument) else ArgumentConstraintPosition(expressionArgument)
|
val position = if (isReceiver) ReceiverConstraintPositionImpl(expressionArgument) else ArgumentConstraintPositionImpl(expressionArgument)
|
||||||
|
|
||||||
// Used only for arguments with @NotNull annotation
|
// Used only for arguments with @NotNull annotation
|
||||||
if (expectedType is NotNullTypeVariable && argumentType.isMarkedNullable) {
|
if (expectedType is NotNullTypeVariable && argumentType.isMarkedNullable) {
|
||||||
@@ -188,7 +188,7 @@ private fun checkSubCallArgument(
|
|||||||
if (expectedType == null) return subCallResult
|
if (expectedType == null) return subCallResult
|
||||||
|
|
||||||
val expectedNullableType = expectedType.makeNullableAsSpecified(true)
|
val expectedNullableType = expectedType.makeNullableAsSpecified(true)
|
||||||
val position = if (receiverInfo.isReceiver) ReceiverConstraintPosition(subCallArgument) else ArgumentConstraintPosition(subCallArgument)
|
val position = if (receiverInfo.isReceiver) ReceiverConstraintPositionImpl(subCallArgument) else ArgumentConstraintPositionImpl(subCallArgument)
|
||||||
|
|
||||||
// subArgument cannot has stable smartcast
|
// subArgument cannot has stable smartcast
|
||||||
// return type can contains fixed type variables
|
// return type can contains fixed type variables
|
||||||
|
|||||||
+3
-3
@@ -82,7 +82,7 @@ class ConstraintIncorporator(
|
|||||||
getConstraintsForVariable(typeVariable).forEach {
|
getConstraintsForVariable(typeVariable).forEach {
|
||||||
if (it.kind != ConstraintKind.LOWER) {
|
if (it.kind != ConstraintKind.LOWER) {
|
||||||
val isFromDeclaredUpperBound =
|
val isFromDeclaredUpperBound =
|
||||||
it.position.from is DeclaredUpperBoundConstraintPosition && it.type.typeConstructor() !is TypeVariableTypeConstructor
|
it.position.from is DeclaredUpperBoundConstraintPosition<*> && it.type.typeConstructor() !is TypeVariableTypeConstructor
|
||||||
|
|
||||||
addNewIncorporatedConstraint(
|
addNewIncorporatedConstraint(
|
||||||
constraint.type,
|
constraint.type,
|
||||||
@@ -227,8 +227,8 @@ class ConstraintIncorporator(
|
|||||||
|
|
||||||
val isUsefulForNullabilityConstraint =
|
val isUsefulForNullabilityConstraint =
|
||||||
isPotentialUsefulNullabilityConstraint(newConstraint, otherConstraint.type, otherConstraint.kind)
|
isPotentialUsefulNullabilityConstraint(newConstraint, otherConstraint.type, otherConstraint.kind)
|
||||||
val isFromVariableFixation = baseConstraint.position.from is FixVariableConstraintPosition
|
val isFromVariableFixation = baseConstraint.position.from is FixVariableConstraintPosition<*>
|
||||||
|| otherConstraint.position.from is FixVariableConstraintPosition
|
|| otherConstraint.position.from is FixVariableConstraintPosition<*>
|
||||||
|
|
||||||
if (!otherConstraint.kind.isEqual() &&
|
if (!otherConstraint.kind.isEqual() &&
|
||||||
!isUsefulForNullabilityConstraint &&
|
!isUsefulForNullabilityConstraint &&
|
||||||
|
|||||||
+1
-1
@@ -124,7 +124,7 @@ class ConstraintInjector(
|
|||||||
return true // T <: T(?!)
|
return true // T <: T(?!)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (constraint.position.from is DeclaredUpperBoundConstraintPosition &&
|
if (constraint.position.from is DeclaredUpperBoundConstraintPosition<*> &&
|
||||||
constraint.kind == UPPER && constraintType.isNullableAny()
|
constraint.kind == UPPER && constraintType.isNullableAny()
|
||||||
) {
|
) {
|
||||||
return true // T <: Any?
|
return true // T <: Any?
|
||||||
|
|||||||
+2
-3
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.types.model.safeSubstitute
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
import kotlin.collections.LinkedHashSet
|
|
||||||
|
|
||||||
class KotlinConstraintSystemCompleter(
|
class KotlinConstraintSystemCompleter(
|
||||||
private val resultTypeResolver: ResultTypeResolver,
|
private val resultTypeResolver: ResultTypeResolver,
|
||||||
@@ -235,7 +234,7 @@ class KotlinConstraintSystemCompleter(
|
|||||||
csBuilder.addSubtypeConstraint(
|
csBuilder.addSubtypeConstraint(
|
||||||
expectedType,
|
expectedType,
|
||||||
functionalType,
|
functionalType,
|
||||||
ArgumentConstraintPosition(atom.atom)
|
ArgumentConstraintPositionImpl(atom.atom)
|
||||||
)
|
)
|
||||||
return atom.transformToResolvedLambda(csBuilder, diagnosticsHolder, expectedType, returnVariable)
|
return atom.transformToResolvedLambda(csBuilder, diagnosticsHolder, expectedType, returnVariable)
|
||||||
}
|
}
|
||||||
@@ -314,7 +313,7 @@ class KotlinConstraintSystemCompleter(
|
|||||||
val resolvedAtom = findResolvedAtomBy(typeVariable, topLevelAtoms) ?: topLevelAtoms.firstOrNull()
|
val resolvedAtom = findResolvedAtomBy(typeVariable, topLevelAtoms) ?: topLevelAtoms.firstOrNull()
|
||||||
|
|
||||||
if (resolvedAtom != null) {
|
if (resolvedAtom != null) {
|
||||||
c.addError(NotEnoughInformationForTypeParameter(typeVariable, resolvedAtom))
|
c.addError(NotEnoughInformationForTypeParameterImpl(typeVariable, resolvedAtom))
|
||||||
}
|
}
|
||||||
|
|
||||||
val resultErrorType = when {
|
val resultErrorType = when {
|
||||||
|
|||||||
+6
-6
@@ -6,13 +6,13 @@
|
|||||||
package org.jetbrains.kotlin.resolve.calls.inference.components
|
package org.jetbrains.kotlin.resolve.calls.inference.components
|
||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.*
|
import org.jetbrains.kotlin.builtins.*
|
||||||
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.transformToResolvedLambda
|
import org.jetbrains.kotlin.resolve.calls.components.transformToResolvedLambda
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
|
||||||
import org.jetbrains.kotlin.utils.SmartSet
|
import org.jetbrains.kotlin.utils.SmartSet
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
@@ -205,13 +205,13 @@ class PostponedArgumentInputTypesResolver(
|
|||||||
if (typeWithKind == null) continue
|
if (typeWithKind == null) continue
|
||||||
when (typeWithKind.direction) {
|
when (typeWithKind.direction) {
|
||||||
ConstraintKind.EQUALITY -> csBuilder.addEqualityConstraint(
|
ConstraintKind.EQUALITY -> csBuilder.addEqualityConstraint(
|
||||||
parameterTypeVariable.defaultType, typeWithKind.type, ArgumentConstraintPosition(atom)
|
parameterTypeVariable.defaultType, typeWithKind.type, ArgumentConstraintPositionImpl(atom)
|
||||||
)
|
)
|
||||||
ConstraintKind.UPPER -> csBuilder.addSubtypeConstraint(
|
ConstraintKind.UPPER -> csBuilder.addSubtypeConstraint(
|
||||||
parameterTypeVariable.defaultType, typeWithKind.type, ArgumentConstraintPosition(atom)
|
parameterTypeVariable.defaultType, typeWithKind.type, ArgumentConstraintPositionImpl(atom)
|
||||||
)
|
)
|
||||||
ConstraintKind.LOWER -> csBuilder.addSubtypeConstraint(
|
ConstraintKind.LOWER -> csBuilder.addSubtypeConstraint(
|
||||||
typeWithKind.type, parameterTypeVariable.defaultType, ArgumentConstraintPosition(atom)
|
typeWithKind.type, parameterTypeVariable.defaultType, ArgumentConstraintPositionImpl(atom)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -330,7 +330,7 @@ class PostponedArgumentInputTypesResolver(
|
|||||||
getBuilder().addSubtypeConstraint(
|
getBuilder().addSubtypeConstraint(
|
||||||
newExpectedType,
|
newExpectedType,
|
||||||
expectedType,
|
expectedType,
|
||||||
ArgumentConstraintPosition(argument.atom)
|
ArgumentConstraintPositionImpl(argument.atom)
|
||||||
)
|
)
|
||||||
|
|
||||||
return newExpectedType
|
return newExpectedType
|
||||||
@@ -486,4 +486,4 @@ class PostponedArgumentInputTypesResolver(
|
|||||||
private const val TYPE_VARIABLE_NAME_PREFIX_FOR_CR_PARAMETER_TYPE = "_QP"
|
private const val TYPE_VARIABLE_NAME_PREFIX_FOR_CR_PARAMETER_TYPE = "_QP"
|
||||||
private const val TYPE_VARIABLE_NAME_FOR_CR_RETURN_TYPE = "_Q"
|
private const val TYPE_VARIABLE_NAME_FOR_CR_RETURN_TYPE = "_Q"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -139,7 +139,7 @@ class VariableFixationFinder(
|
|||||||
|
|
||||||
private fun Context.isProperArgumentConstraint(c: Constraint) =
|
private fun Context.isProperArgumentConstraint(c: Constraint) =
|
||||||
isProperType(c.type)
|
isProperType(c.type)
|
||||||
&& c.position.initialConstraint.position !is DeclaredUpperBoundConstraintPosition
|
&& c.position.initialConstraint.position !is DeclaredUpperBoundConstraintPosition<*>
|
||||||
&& !c.isNullabilityConstraint
|
&& !c.isNullabilityConstraint
|
||||||
|
|
||||||
private fun Context.isProperType(type: KotlinTypeMarker): Boolean =
|
private fun Context.isProperType(type: KotlinTypeMarker): Boolean =
|
||||||
@@ -162,4 +162,4 @@ inline fun TypeSystemInferenceExtensionContext.isProperTypeForFixation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-36
@@ -16,69 +16,62 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.calls.inference.model
|
package org.jetbrains.kotlin.resolve.calls.inference.model
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.resolve.calls.model.DiagnosticReporter
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability
|
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.*
|
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.*
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.DetailedReceiver
|
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||||
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
||||||
|
|
||||||
|
interface OnlyInputTypeConstraintPosition
|
||||||
|
|
||||||
sealed class ConstraintPosition
|
sealed class ConstraintPosition
|
||||||
|
|
||||||
class ExplicitTypeParameterConstraintPosition(val typeArgument: SimpleTypeArgument) : ConstraintPosition(), OnlyInputTypeConstraintPosition {
|
abstract class ExplicitTypeParameterConstraintPosition<T>(val typeArgument: T) : ConstraintPosition(), OnlyInputTypeConstraintPosition {
|
||||||
override fun toString() = "TypeParameter $typeArgument"
|
override fun toString(): String = "TypeParameter $typeArgument"
|
||||||
}
|
}
|
||||||
|
|
||||||
class ExpectedTypeConstraintPosition(val topLevelCall: KotlinCall) : ConstraintPosition(), OnlyInputTypeConstraintPosition {
|
abstract class ExpectedTypeConstraintPosition<T>(val topLevelCall: T) : ConstraintPosition(), OnlyInputTypeConstraintPosition {
|
||||||
override fun toString() = "ExpectedType for call $topLevelCall"
|
override fun toString(): String = "ExpectedType for call $topLevelCall"
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class DeclaredUpperBoundConstraintPosition : ConstraintPosition()
|
abstract class DeclaredUpperBoundConstraintPosition<T>(val typeParameter: T) : ConstraintPosition() {
|
||||||
|
override fun toString(): String = "DeclaredUpperBound $typeParameter"
|
||||||
class DeclaredUpperBoundConstraintPositionImpl(val typeParameterDescriptor: TypeParameterDescriptor) : DeclaredUpperBoundConstraintPosition() {
|
|
||||||
override fun toString() = "DeclaredUpperBound ${typeParameterDescriptor.name} from ${typeParameterDescriptor.containingDeclaration}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FirDeclaredUpperBoundConstraintPosition : DeclaredUpperBoundConstraintPosition()
|
abstract class ArgumentConstraintPosition<T>(val argument: T) : ConstraintPosition(), OnlyInputTypeConstraintPosition {
|
||||||
|
override fun toString(): String = "Argument $argument"
|
||||||
interface OnlyInputTypeConstraintPosition
|
|
||||||
|
|
||||||
class ArgumentConstraintPosition(val argument: KotlinCallArgument) : ConstraintPosition(), OnlyInputTypeConstraintPosition {
|
|
||||||
override fun toString() = "Argument $argument"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ReceiverConstraintPosition(val argument: KotlinCallArgument) : ConstraintPosition(), OnlyInputTypeConstraintPosition {
|
abstract class ReceiverConstraintPosition<T>(val argument: T) : ConstraintPosition(), OnlyInputTypeConstraintPosition {
|
||||||
override fun toString() = "Receiver $argument"
|
override fun toString(): String = "Receiver $argument"
|
||||||
}
|
}
|
||||||
|
|
||||||
class FixVariableConstraintPosition(val variable: TypeVariableMarker, val resolvedAtom: ResolvedAtom?) : ConstraintPosition() {
|
abstract class FixVariableConstraintPosition<T>(val variable: TypeVariableMarker, val resolvedAtom: T) : ConstraintPosition() {
|
||||||
override fun toString() = "Fix variable $variable"
|
override fun toString(): String = "Fix variable $variable"
|
||||||
}
|
}
|
||||||
|
|
||||||
class KnownTypeParameterConstraintPosition(val typeArgument: KotlinType) : ConstraintPosition() {
|
abstract class KnownTypeParameterConstraintPosition<T : KotlinTypeMarker>(val typeArgument: T) : ConstraintPosition() {
|
||||||
override fun toString() = "TypeArgument $typeArgument"
|
override fun toString(): String = "TypeArgument $typeArgument"
|
||||||
}
|
}
|
||||||
|
|
||||||
class LHSArgumentConstraintPosition(
|
abstract class LHSArgumentConstraintPosition<T, R>(
|
||||||
val argument: CallableReferenceKotlinCallArgument,
|
val argument: T,
|
||||||
val receiver: DetailedReceiver
|
val receiver: R
|
||||||
) : ConstraintPosition() {
|
) : ConstraintPosition() {
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "LHS receiver $receiver"
|
return "LHS receiver $receiver"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LambdaArgumentConstraintPosition(val lambda: ResolvedLambdaAtom) : ConstraintPosition() {
|
abstract class LambdaArgumentConstraintPosition<T>(val lambda: T) : ConstraintPosition() {
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "LambdaArgument $lambda"
|
return "LambdaArgument $lambda"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DelegatedPropertyConstraintPosition(val topLevelCall: KotlinCall) : ConstraintPosition() {
|
abstract class DelegatedPropertyConstraintPosition<T>(val topLevelCall: T) : ConstraintPosition() {
|
||||||
override fun toString() = "Constraint from call $topLevelCall for delegated property"
|
override fun toString(): String = "Constraint from call $topLevelCall for delegated property"
|
||||||
}
|
}
|
||||||
|
|
||||||
data class IncorporationConstraintPosition(
|
data class IncorporationConstraintPosition(
|
||||||
@@ -86,11 +79,10 @@ data class IncorporationConstraintPosition(
|
|||||||
val initialConstraint: InitialConstraint,
|
val initialConstraint: InitialConstraint,
|
||||||
var isFromDeclaredUpperBound: Boolean = false
|
var isFromDeclaredUpperBound: Boolean = false
|
||||||
) : ConstraintPosition() {
|
) : ConstraintPosition() {
|
||||||
override fun toString() =
|
override fun toString(): String = "Incorporate $initialConstraint from position $from"
|
||||||
"Incorporate $initialConstraint from position $from"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class CoroutinePosition() : ConstraintPosition() {
|
object CoroutinePosition : ConstraintPosition() {
|
||||||
override fun toString(): String = "for coroutine call"
|
override fun toString(): String = "for coroutine call"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +97,7 @@ class NewConstraintError(
|
|||||||
val lowerType: KotlinTypeMarker,
|
val lowerType: KotlinTypeMarker,
|
||||||
val upperType: KotlinTypeMarker,
|
val upperType: KotlinTypeMarker,
|
||||||
val position: IncorporationConstraintPosition
|
val position: IncorporationConstraintPosition
|
||||||
) : ConstraintSystemCallDiagnostic(if (position.from is ReceiverConstraintPosition) INAPPLICABLE_WRONG_RECEIVER else INAPPLICABLE)
|
) : ConstraintSystemCallDiagnostic(if (position.from is ReceiverConstraintPosition<*>) INAPPLICABLE_WRONG_RECEIVER else INAPPLICABLE)
|
||||||
|
|
||||||
class CapturedTypeFromSubtyping(
|
class CapturedTypeFromSubtyping(
|
||||||
val typeVariable: TypeVariableMarker,
|
val typeVariable: TypeVariableMarker,
|
||||||
@@ -113,9 +105,9 @@ class CapturedTypeFromSubtyping(
|
|||||||
val position: ConstraintPosition
|
val position: ConstraintPosition
|
||||||
) : ConstraintSystemCallDiagnostic(INAPPLICABLE)
|
) : ConstraintSystemCallDiagnostic(INAPPLICABLE)
|
||||||
|
|
||||||
class NotEnoughInformationForTypeParameter(
|
abstract class NotEnoughInformationForTypeParameter<T>(
|
||||||
val typeVariable: TypeVariableMarker,
|
val typeVariable: TypeVariableMarker,
|
||||||
val resolvedAtom: ResolvedAtom
|
val resolvedAtom: T
|
||||||
) : ConstraintSystemCallDiagnostic(INAPPLICABLE)
|
) : ConstraintSystemCallDiagnostic(INAPPLICABLE)
|
||||||
|
|
||||||
class ConstrainingTypeIsError(
|
class ConstrainingTypeIsError(
|
||||||
|
|||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.resolve.calls.inference.model
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
|
import org.jetbrains.kotlin.resolve.scopes.receivers.DetailedReceiver
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
||||||
|
|
||||||
|
class ExplicitTypeParameterConstraintPositionImpl(
|
||||||
|
typeArgument: SimpleTypeArgument
|
||||||
|
) : ExplicitTypeParameterConstraintPosition<SimpleTypeArgument>(typeArgument)
|
||||||
|
|
||||||
|
class ExpectedTypeConstraintPositionImpl(topLevelCall: KotlinCall) : ExpectedTypeConstraintPosition<KotlinCall>(topLevelCall)
|
||||||
|
|
||||||
|
class DeclaredUpperBoundConstraintPositionImpl(
|
||||||
|
typeParameter: TypeParameterDescriptor
|
||||||
|
) : DeclaredUpperBoundConstraintPosition<TypeParameterDescriptor>(typeParameter) {
|
||||||
|
override fun toString() = "DeclaredUpperBound ${typeParameter.name} from ${typeParameter.containingDeclaration}"
|
||||||
|
}
|
||||||
|
|
||||||
|
class ArgumentConstraintPositionImpl(argument: KotlinCallArgument) : ArgumentConstraintPosition<KotlinCallArgument>(argument)
|
||||||
|
|
||||||
|
class ReceiverConstraintPositionImpl(argument: KotlinCallArgument) : ReceiverConstraintPosition<KotlinCallArgument>(argument)
|
||||||
|
|
||||||
|
class FixVariableConstraintPositionImpl(
|
||||||
|
variable: TypeVariableMarker,
|
||||||
|
resolvedAtom: ResolvedAtom?
|
||||||
|
) : FixVariableConstraintPosition<ResolvedAtom?>(variable, resolvedAtom)
|
||||||
|
|
||||||
|
class KnownTypeParameterConstraintPositionImpl(typeArgument: KotlinType) : KnownTypeParameterConstraintPosition<KotlinType>(typeArgument)
|
||||||
|
|
||||||
|
class LHSArgumentConstraintPositionImpl(
|
||||||
|
argument: CallableReferenceKotlinCallArgument,
|
||||||
|
receiver: DetailedReceiver
|
||||||
|
) : LHSArgumentConstraintPosition<CallableReferenceKotlinCallArgument, DetailedReceiver>(argument, receiver)
|
||||||
|
|
||||||
|
class LambdaArgumentConstraintPositionImpl(lambda: ResolvedLambdaAtom) : LambdaArgumentConstraintPosition<ResolvedLambdaAtom>(lambda)
|
||||||
|
|
||||||
|
class DelegatedPropertyConstraintPositionImpl(topLevelCall: KotlinCall) : DelegatedPropertyConstraintPosition<KotlinCall>(topLevelCall)
|
||||||
|
|
||||||
|
class NotEnoughInformationForTypeParameterImpl(
|
||||||
|
typeVariable: TypeVariableMarker,
|
||||||
|
resolvedAtom: ResolvedAtom
|
||||||
|
) : NotEnoughInformationForTypeParameter<ResolvedAtom>(typeVariable, resolvedAtom)
|
||||||
+1
-1
@@ -115,7 +115,7 @@ class MutableVariableWithConstraints private constructor(
|
|||||||
private fun newConstraintIsUseless(old: Constraint, new: Constraint): Boolean {
|
private fun newConstraintIsUseless(old: Constraint, new: Constraint): Boolean {
|
||||||
// Constraints from declared upper bound are quite special -- they aren't considered as a proper ones
|
// Constraints from declared upper bound are quite special -- they aren't considered as a proper ones
|
||||||
// In other words, user-defined constraints have "higher" priority and here we're trying not to loose them
|
// In other words, user-defined constraints have "higher" priority and here we're trying not to loose them
|
||||||
if (old.position.from is DeclaredUpperBoundConstraintPosition && new.position.from !is DeclaredUpperBoundConstraintPosition)
|
if (old.position.from is DeclaredUpperBoundConstraintPosition<*> && new.position.from !is DeclaredUpperBoundConstraintPosition<*>)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
return when (old.kind) {
|
return when (old.kind) {
|
||||||
|
|||||||
+1
-1
@@ -302,7 +302,7 @@ class NewConstraintSystemImpl(
|
|||||||
checkState(State.BUILDING, State.COMPLETION)
|
checkState(State.BUILDING, State.COMPLETION)
|
||||||
|
|
||||||
constraintInjector.addInitialEqualityConstraint(
|
constraintInjector.addInitialEqualityConstraint(
|
||||||
this, variable.defaultType(), resultType, FixVariableConstraintPosition(variable, atom)
|
this, variable.defaultType(), resultType, FixVariableConstraintPositionImpl(variable, atom)
|
||||||
)
|
)
|
||||||
|
|
||||||
val freshTypeConstructor = variable.freshTypeConstructor()
|
val freshTypeConstructor = variable.freshTypeConstructor()
|
||||||
|
|||||||
Reference in New Issue
Block a user