Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.resolve.calls.tower.CandidateApplicability
import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability.*
import org.jetbrains.kotlin.types.EmptyIntersectionTypeKind
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
import org.jetbrains.kotlin.types.model.TypeVariableMarker
interface OnlyInputTypeConstraintPosition
sealed class ConstraintPosition
abstract class ExplicitTypeParameterConstraintPosition(val typeArgument: T) : ConstraintPosition(), OnlyInputTypeConstraintPosition {
override fun toString(): String = "TypeParameter $typeArgument"
}
abstract class InjectedAnotherStubTypeConstraintPosition(private val builderInferenceLambdaOfInjectedStubType: T) : ConstraintPosition(),
OnlyInputTypeConstraintPosition {
override fun toString(): String = "Injected from $builderInferenceLambdaOfInjectedStubType builder inference call"
}
abstract class BuilderInferenceSubstitutionConstraintPosition(
private val builderInferenceLambda: L,
val initialConstraint: I,
val isFromNotSubstitutedDeclaredUpperBound: Boolean = false
) : ConstraintPosition(), OnlyInputTypeConstraintPosition {
override fun toString(): String = "Incorporated builder inference constraint $initialConstraint " +
"into $builderInferenceLambda call"
}
abstract class ExpectedTypeConstraintPosition(val topLevelCall: T) : ConstraintPosition(), OnlyInputTypeConstraintPosition {
override fun toString(): String = "ExpectedType for call $topLevelCall"
}
abstract class DeclaredUpperBoundConstraintPosition(val typeParameter: T) : ConstraintPosition() {
override fun toString(): String = "DeclaredUpperBound $typeParameter"
}
abstract class ArgumentConstraintPosition(val argument: T) : ConstraintPosition(), OnlyInputTypeConstraintPosition {
override fun toString(): String = "Argument $argument"
}
abstract class CallableReferenceConstraintPosition(val call: T) : ConstraintPosition(), OnlyInputTypeConstraintPosition {
override fun toString(): String = "Callable reference $call"
}
abstract class ReceiverConstraintPosition(val argument: T) : ConstraintPosition(), OnlyInputTypeConstraintPosition {
override fun toString(): String = "Receiver $argument"
}
abstract class FixVariableConstraintPosition(val variable: TypeVariableMarker, val resolvedAtom: T) : ConstraintPosition() {
override fun toString(): String = "Fix variable $variable"
}
abstract class KnownTypeParameterConstraintPosition(val typeArgument: T) : ConstraintPosition() {
override fun toString(): String = "TypeArgument $typeArgument"
}
abstract class LHSArgumentConstraintPosition(
val argument: T,
val receiver: R
) : ConstraintPosition() {
override fun toString(): String {
return "LHS receiver $receiver"
}
}
abstract class LambdaArgumentConstraintPosition(val lambda: T) : ConstraintPosition() {
override fun toString(): String {
return "LambdaArgument $lambda"
}
}
open class DelegatedPropertyConstraintPosition(val topLevelCall: T) : ConstraintPosition() {
override fun toString(): String = "Constraint from call $topLevelCall for delegated property"
}
data class IncorporationConstraintPosition(
val initialConstraint: InitialConstraint,
var isFromDeclaredUpperBound: Boolean = false
) : ConstraintPosition() {
val from: ConstraintPosition get() = initialConstraint.position
override fun toString(): String = "Incorporate $initialConstraint from position $from"
}
object BuilderInferencePosition : ConstraintPosition() {
override fun toString(): String = "For builder inference call"
}
// TODO: should be used only in SimpleConstraintSystemImpl
object SimpleConstraintSystemConstraintPosition : ConstraintPosition()
// ------------------------------------------------ Errors ------------------------------------------------
sealed class ConstraintSystemError(val applicability: CandidateApplicability)
sealed interface NewConstraintMismatch {
val lowerType: KotlinTypeMarker
val upperType: KotlinTypeMarker
val position: IncorporationConstraintPosition
}
class NewConstraintError(
override val lowerType: KotlinTypeMarker,
override val upperType: KotlinTypeMarker,
override val position: IncorporationConstraintPosition,
) : ConstraintSystemError(if (position.from is ReceiverConstraintPosition<*>) INAPPLICABLE_WRONG_RECEIVER else INAPPLICABLE),
NewConstraintMismatch
class NewConstraintWarning(
override val lowerType: KotlinTypeMarker,
override val upperType: KotlinTypeMarker,
override val position: IncorporationConstraintPosition,
) : ConstraintSystemError(RESOLVED), NewConstraintMismatch
class CapturedTypeFromSubtyping(
val typeVariable: TypeVariableMarker,
val constraintType: KotlinTypeMarker,
val position: ConstraintPosition
) : ConstraintSystemError(INAPPLICABLE)
open class NotEnoughInformationForTypeParameter(
val typeVariable: TypeVariableMarker,
val resolvedAtom: T,
val couldBeResolvedWithUnrestrictedBuilderInference: Boolean
) : ConstraintSystemError(INAPPLICABLE)
class InferredIntoDeclaredUpperBounds(val typeVariable: TypeVariableMarker) : ConstraintSystemError(RESOLVED)
class ConstrainingTypeIsError(
val typeVariable: TypeVariableMarker,
val constraintType: KotlinTypeMarker,
val position: IncorporationConstraintPosition
) : ConstraintSystemError(INAPPLICABLE)
class NoSuccessfulFork(val position: IncorporationConstraintPosition) : ConstraintSystemError(INAPPLICABLE)
sealed interface InferredEmptyIntersection {
val incompatibleTypes: List
val causingTypes: List
val typeVariable: TypeVariableMarker
val kind: EmptyIntersectionTypeKind
}
class InferredEmptyIntersectionWarning(
override val incompatibleTypes: List,
override val causingTypes: List,
override val typeVariable: TypeVariableMarker,
override val kind: EmptyIntersectionTypeKind,
) : ConstraintSystemError(RESOLVED), InferredEmptyIntersection
class InferredEmptyIntersectionError(
override val incompatibleTypes: List,
override val causingTypes: List,
override val typeVariable: TypeVariableMarker,
override val kind: EmptyIntersectionTypeKind,
) : ConstraintSystemError(INAPPLICABLE), InferredEmptyIntersection
class OnlyInputTypesDiagnostic(val typeVariable: TypeVariableMarker) : ConstraintSystemError(INAPPLICABLE)
class LowerPriorityToPreserveCompatibility(val needToReportWarning: Boolean) :
ConstraintSystemError(RESOLVED_NEED_PRESERVE_COMPATIBILITY)
fun Constraint.isExpectedTypePosition() =
position.from is ExpectedTypeConstraintPosition<*> || position.from is DelegatedPropertyConstraintPosition<*>
fun NewConstraintError.transformToWarning() = NewConstraintWarning(lowerType, upperType, position)