[NI] Split KotlinCallDiagnostics and inference errors to different hierarchies
This commit is contained in:
+1
-1
@@ -236,7 +236,7 @@ class KotlinCallCompleter(
|
||||
}
|
||||
}
|
||||
|
||||
constraintSystem.diagnostics.forEach(diagnosticsHolder::addDiagnostic)
|
||||
constraintSystem.diagnostics.forEach(diagnosticsHolder::addError)
|
||||
}
|
||||
|
||||
private fun prepareCandidateForCompletion(
|
||||
|
||||
+2
-2
@@ -20,11 +20,11 @@ import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.PostponedArgumentInputTypesResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError
|
||||
|
||||
interface NewConstraintSystem {
|
||||
val hasContradiction: Boolean
|
||||
val diagnostics: List<KotlinCallDiagnostic>
|
||||
val diagnostics: List<ConstraintSystemError>
|
||||
|
||||
fun getBuilder(): ConstraintSystemBuilder
|
||||
|
||||
|
||||
+1
-2
@@ -20,7 +20,6 @@ package org.jetbrains.kotlin.resolve.calls.inference.components
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind.*
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
@@ -43,7 +42,7 @@ class ConstraintInjector(
|
||||
val fixedTypeVariables: MutableMap<TypeConstructorMarker, KotlinTypeMarker>
|
||||
|
||||
fun addInitialConstraint(initialConstraint: InitialConstraint)
|
||||
fun addError(error: KotlinCallDiagnostic)
|
||||
fun addError(error: ConstraintSystemError)
|
||||
}
|
||||
|
||||
fun addInitialSubtypeConstraint(c: Context, lowerType: KotlinTypeMarker, upperType: KotlinTypeMarker, position: ConstraintPosition) {
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ class KotlinConstraintSystemCompleter(
|
||||
fun containsOnlyFixedOrPostponedVariables(type: KotlinTypeMarker): Boolean
|
||||
|
||||
// mutable operations
|
||||
fun addError(error: KotlinCallDiagnostic)
|
||||
fun addError(error: ConstraintSystemError)
|
||||
|
||||
fun fixVariable(variable: TypeVariableMarker, resultType: KotlinTypeMarker, atom: ResolvedAtom?)
|
||||
|
||||
|
||||
+10
-10
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.inference.model
|
||||
|
||||
import org.jetbrains.kotlin.resolve.calls.model.DiagnosticReporter
|
||||
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.types.model.KotlinTypeMarker
|
||||
@@ -89,31 +87,33 @@ object CoroutinePosition : ConstraintPosition() {
|
||||
// TODO: should be used only in SimpleConstraintSystemImpl
|
||||
object SimpleConstraintSystemConstraintPosition : ConstraintPosition()
|
||||
|
||||
abstract class ConstraintSystemCallDiagnostic(applicability: ResolutionCandidateApplicability) : KotlinCallDiagnostic(applicability) {
|
||||
override fun report(reporter: DiagnosticReporter) = reporter.constraintError(this)
|
||||
}
|
||||
// ------------------------------------------------ Errors ------------------------------------------------
|
||||
|
||||
sealed class ConstraintSystemError(val applicability: ResolutionCandidateApplicability)
|
||||
|
||||
class NewConstraintError(
|
||||
val lowerType: KotlinTypeMarker,
|
||||
val upperType: KotlinTypeMarker,
|
||||
val position: IncorporationConstraintPosition
|
||||
) : ConstraintSystemCallDiagnostic(if (position.from is ReceiverConstraintPosition<*>) INAPPLICABLE_WRONG_RECEIVER else INAPPLICABLE)
|
||||
) : ConstraintSystemError(if (position.from is ReceiverConstraintPosition<*>) INAPPLICABLE_WRONG_RECEIVER else INAPPLICABLE)
|
||||
|
||||
class CapturedTypeFromSubtyping(
|
||||
val typeVariable: TypeVariableMarker,
|
||||
val constraintType: KotlinTypeMarker,
|
||||
val position: ConstraintPosition
|
||||
) : ConstraintSystemCallDiagnostic(INAPPLICABLE)
|
||||
) : ConstraintSystemError(INAPPLICABLE)
|
||||
|
||||
abstract class NotEnoughInformationForTypeParameter<T>(
|
||||
val typeVariable: TypeVariableMarker,
|
||||
val resolvedAtom: T
|
||||
) : ConstraintSystemCallDiagnostic(INAPPLICABLE)
|
||||
) : ConstraintSystemError(INAPPLICABLE)
|
||||
|
||||
class ConstrainingTypeIsError(
|
||||
val typeVariable: TypeVariableMarker,
|
||||
val constraintType: KotlinTypeMarker,
|
||||
val position: IncorporationConstraintPosition
|
||||
) : ConstraintSystemCallDiagnostic(INAPPLICABLE)
|
||||
) : ConstraintSystemError(INAPPLICABLE)
|
||||
|
||||
object LowerPriorityToPreserveCompatibility : ConstraintSystemCallDiagnostic(RESOLVED_NEED_PRESERVE_COMPATIBILITY)
|
||||
class OnlyInputTypesDiagnostic(val typeVariable: TypeVariableMarker) : ConstraintSystemError(INAPPLICABLE)
|
||||
|
||||
object LowerPriorityToPreserveCompatibility : ConstraintSystemError(RESOLVED_NEED_PRESERVE_COMPATIBILITY)
|
||||
|
||||
+7
-5
@@ -5,9 +5,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.inference.model
|
||||
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.model.*
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeCheckerProviderContext
|
||||
import org.jetbrains.kotlin.types.model.TypeConstructorMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
||||
|
||||
/**
|
||||
* Every type variable can be in the following states:
|
||||
@@ -36,7 +38,7 @@ interface ConstraintStorage {
|
||||
val notFixedTypeVariables: Map<TypeConstructorMarker, VariableWithConstraints>
|
||||
val initialConstraints: List<InitialConstraint>
|
||||
val maxTypeDepthFromInitialConstraints: Int
|
||||
val errors: List<KotlinCallDiagnostic>
|
||||
val errors: List<ConstraintSystemError>
|
||||
val hasContradiction: Boolean
|
||||
val fixedTypeVariables: Map<TypeConstructorMarker, KotlinTypeMarker>
|
||||
val postponedTypeVariables: List<TypeVariableMarker>
|
||||
@@ -46,7 +48,7 @@ interface ConstraintStorage {
|
||||
override val notFixedTypeVariables: Map<TypeConstructorMarker, VariableWithConstraints> get() = emptyMap()
|
||||
override val initialConstraints: List<InitialConstraint> get() = emptyList()
|
||||
override val maxTypeDepthFromInitialConstraints: Int get() = 1
|
||||
override val errors: List<KotlinCallDiagnostic> get() = emptyList()
|
||||
override val errors: List<ConstraintSystemError> get() = emptyList()
|
||||
override val hasContradiction: Boolean get() = false
|
||||
override val fixedTypeVariables: Map<TypeConstructorMarker, KotlinTypeMarker> get() = emptyMap()
|
||||
override val postponedTypeVariables: List<TypeVariableMarker> get() = emptyList()
|
||||
@@ -139,4 +141,4 @@ fun checkConstraint(
|
||||
ConstraintKind.LOWER -> typeChecker.isSubtypeOf(context, constraintType, resultType)
|
||||
ConstraintKind.UPPER -> typeChecker.isSubtypeOf(context, resultType, constraintType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.inference.model
|
||||
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
@@ -191,8 +190,8 @@ internal class MutableConstraintStorage : ConstraintStorage {
|
||||
override val notFixedTypeVariables: MutableMap<TypeConstructorMarker, MutableVariableWithConstraints> = LinkedHashMap()
|
||||
override val initialConstraints: MutableList<InitialConstraint> = SmartList()
|
||||
override var maxTypeDepthFromInitialConstraints: Int = 1
|
||||
override val errors: MutableList<KotlinCallDiagnostic> = SmartList()
|
||||
override val hasContradiction: Boolean get() = errors.any { !it.candidateApplicability.isSuccess }
|
||||
override val errors: MutableList<ConstraintSystemError> = SmartList()
|
||||
override val hasContradiction: Boolean get() = errors.any { !it.applicability.isSuccess }
|
||||
override val fixedTypeVariables: MutableMap<TypeConstructorMarker, KotlinTypeMarker> = LinkedHashMap()
|
||||
override val postponedTypeVariables: MutableList<TypeVariableMarker> = SmartList()
|
||||
}
|
||||
|
||||
+2
-4
@@ -11,8 +11,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjecto
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.PostponedArgumentInputTypesResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ResultTypeResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
|
||||
import org.jetbrains.kotlin.resolve.calls.model.OnlyInputTypesDiagnostic
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedAtom
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker
|
||||
@@ -75,7 +73,7 @@ class NewConstraintSystemImpl(
|
||||
}
|
||||
}
|
||||
|
||||
override val diagnostics: List<KotlinCallDiagnostic>
|
||||
override val diagnostics: List<ConstraintSystemError>
|
||||
get() = storage.errors
|
||||
|
||||
override fun getBuilder() = apply { checkState(State.BUILDING, State.COMPLETION, State.TRANSACTION) }
|
||||
@@ -291,7 +289,7 @@ class NewConstraintSystemImpl(
|
||||
}
|
||||
|
||||
// ConstraintInjector.Context, KotlinConstraintSystemCompleter.Context
|
||||
override fun addError(error: KotlinCallDiagnostic) {
|
||||
override fun addError(error: ConstraintSystemError) {
|
||||
checkState(State.BUILDING, State.COMPLETION, State.TRANSACTION)
|
||||
storage.errors.add(error)
|
||||
}
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.model
|
||||
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.INAPPLICABLE
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
abstract class KotlinCallDiagnostic(val candidateApplicability: ResolutionCandidateApplicability) {
|
||||
abstract fun report(reporter: DiagnosticReporter)
|
||||
@@ -41,5 +40,5 @@ interface DiagnosticReporter {
|
||||
fun onCallArgumentName(callArgument: KotlinCallArgument, diagnostic: KotlinCallDiagnostic)
|
||||
fun onCallArgumentSpread(callArgument: KotlinCallArgument, diagnostic: KotlinCallDiagnostic)
|
||||
|
||||
fun constraintError(diagnostic: KotlinCallDiagnostic)
|
||||
fun constraintError(error: ConstraintSystemError)
|
||||
}
|
||||
|
||||
+14
-8
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceCandidate
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.*
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
@@ -223,12 +223,6 @@ class ArgumentTypeMismatchDiagnostic(
|
||||
}
|
||||
}
|
||||
|
||||
class OnlyInputTypesDiagnostic(val typeVariable: NewTypeVariable) : KotlinCallDiagnostic(INAPPLICABLE) {
|
||||
override fun report(reporter: DiagnosticReporter) {
|
||||
reporter.onCall(this)
|
||||
}
|
||||
}
|
||||
|
||||
class ResolvedToSamWithVarargDiagnostic(val argument: KotlinCallArgument) : KotlinCallDiagnostic(RESOLVED_TO_SAM_WITH_VARARG) {
|
||||
override fun report(reporter: DiagnosticReporter) {
|
||||
reporter.onCallArgument(argument, this)
|
||||
@@ -272,4 +266,16 @@ class AdaptedCallableReferenceIsUsedWithReflection(
|
||||
reporter.onCallArgument(argument, this)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class KotlinConstraintSystemDiagnostic(
|
||||
val error: ConstraintSystemError
|
||||
) : KotlinCallDiagnostic(error.applicability) {
|
||||
override fun report(reporter: DiagnosticReporter) = reporter.constraintError(error)
|
||||
}
|
||||
|
||||
val KotlinCallDiagnostic.constraintSystemError: ConstraintSystemError?
|
||||
get() = (this as? KotlinConstraintSystemDiagnostic)?.error
|
||||
|
||||
fun ConstraintSystemError.asDiagnostic(): KotlinConstraintSystemDiagnostic = KotlinConstraintSystemDiagnostic(this)
|
||||
fun Collection<ConstraintSystemError>.asDiagnostics(): List<KotlinConstraintSystemDiagnostic> = map(ConstraintSystemError::asDiagnostic)
|
||||
|
||||
@@ -237,16 +237,17 @@ sealed class CallResolutionResult(
|
||||
|
||||
fun completedDiagnostic(substitutor: NewTypeSubstitutor): List<KotlinCallDiagnostic> {
|
||||
return diagnostics.map {
|
||||
if (it !is NewConstraintError) return@map it
|
||||
val lowerType = it.lowerType.safeAs<KotlinType>()?.unwrap() ?: return@map it
|
||||
val error = it.constraintSystemError ?: return@map it
|
||||
if (error !is NewConstraintError) return@map it
|
||||
val lowerType = error.lowerType.safeAs<KotlinType>()?.unwrap() ?: return@map it
|
||||
val newLowerType = substitutor.safeSubstitute(lowerType.unCapture())
|
||||
NewConstraintError(newLowerType, it.upperType, it.position)
|
||||
NewConstraintError(newLowerType, error.upperType, error.position).asDiagnostic()
|
||||
}
|
||||
}
|
||||
|
||||
override val atom: ResolutionAtom? get() = null
|
||||
|
||||
override fun toString() = "diagnostics: (${diagnostics.joinToString()})"
|
||||
override fun toString(): String = "diagnostics: (${diagnostics.joinToString()})"
|
||||
}
|
||||
|
||||
open class SingleCallResolutionResult(
|
||||
|
||||
+7
-2
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.resolve.calls.components.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintStorage
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.LowerPriorityToPreserveCompatibility
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
@@ -62,6 +63,10 @@ fun KotlinDiagnosticsHolder.addDiagnosticIfNotNull(diagnostic: KotlinCallDiagnos
|
||||
diagnostic?.let { addDiagnostic(it) }
|
||||
}
|
||||
|
||||
fun KotlinDiagnosticsHolder.addError(error: ConstraintSystemError) {
|
||||
addDiagnostic(error.asDiagnostic())
|
||||
}
|
||||
|
||||
/**
|
||||
* baseSystem contains all information from arguments, i.e. it is union of all system of arguments
|
||||
* Also by convention we suppose that baseSystem has no contradiction
|
||||
@@ -252,10 +257,10 @@ class MutableResolvedCallAtom(
|
||||
|
||||
fun KotlinResolutionCandidate.markCandidateForCompatibilityResolve() {
|
||||
if (callComponents.languageVersionSettings.supportsFeature(LanguageFeature.DisableCompatibilityModeForNewInference)) return
|
||||
addDiagnostic(LowerPriorityToPreserveCompatibility)
|
||||
addDiagnostic(LowerPriorityToPreserveCompatibility.asDiagnostic())
|
||||
}
|
||||
|
||||
fun CallableReferencesCandidateFactory.markCandidateForCompatibilityResolve(diagnostics: SmartList<KotlinCallDiagnostic>) {
|
||||
if (callComponents.languageVersionSettings.supportsFeature(LanguageFeature.DisableCompatibilityModeForNewInference)) return
|
||||
diagnostics.add(LowerPriorityToPreserveCompatibility)
|
||||
diagnostics.add(LowerPriorityToPreserveCompatibility.asDiagnostic())
|
||||
}
|
||||
|
||||
+8
-2
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.calls.tower
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError
|
||||
import org.jetbrains.kotlin.resolve.calls.model.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.*
|
||||
@@ -88,8 +89,13 @@ class CandidateWithBoundDispatchReceiver(
|
||||
val diagnostics: List<ResolutionDiagnostic>
|
||||
)
|
||||
|
||||
fun getResultApplicability(diagnostics: Collection<KotlinCallDiagnostic>) =
|
||||
diagnostics.maxOfOrNull { it.candidateApplicability } ?: RESOLVED
|
||||
@JvmName("getResultApplicabilityForConstraintErrors")
|
||||
fun getResultApplicability(diagnostics: Collection<ConstraintSystemError>): ResolutionCandidateApplicability =
|
||||
diagnostics.maxByOrNull { it.applicability }?.applicability ?: RESOLVED
|
||||
|
||||
@JvmName("getResultApplicabilityForCallDiagnostics")
|
||||
fun getResultApplicability(diagnostics: Collection<KotlinCallDiagnostic>): ResolutionCandidateApplicability =
|
||||
diagnostics.maxByOrNull { it.candidateApplicability }?.candidateApplicability ?: RESOLVED
|
||||
|
||||
enum class ResolutionCandidateApplicability {
|
||||
RESOLVED, // call success or has uncompleted inference or in other words possible successful candidate
|
||||
|
||||
Reference in New Issue
Block a user