[NI] Move most of KotlinCallDiagnostic to one file
Now there is 3 kind of KotlinCallDiagnostic: - ResolutionDiagnostic - ConstraintSystemCallDiagnostic - other common diagnostic Also SpecialResolutionParts were merged into other ResolutionParts
This commit is contained in:
committed by
Mikhail Zarechenskiy
parent
9378bff65c
commit
ef93088a42
+2
-3
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.diagnostics.Errors.BadNamedArgumentsTarget.*
|
|||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
import org.jetbrains.kotlin.resolve.calls.components.*
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||||
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.*
|
||||||
@@ -123,7 +122,7 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun reportSmartCast(smartCastDiagnostic: SmartCastDiagnostic) {
|
private fun reportSmartCast(smartCastDiagnostic: SmartCastDiagnostic) {
|
||||||
val expressionArgument = smartCastDiagnostic.expressionArgument
|
val expressionArgument = smartCastDiagnostic.argument
|
||||||
if (expressionArgument is ExpressionKotlinCallArgumentImpl) {
|
if (expressionArgument is ExpressionKotlinCallArgumentImpl) {
|
||||||
val context = context.replaceDataFlowInfo(expressionArgument.dataFlowInfoBeforeThisArgument)
|
val context = context.replaceDataFlowInfo(expressionArgument.dataFlowInfoBeforeThisArgument)
|
||||||
val argumentExpression = KtPsiUtil.getLastElementDeparenthesized(expressionArgument.valueArgument.getArgumentExpression (), context.statementFilter)
|
val argumentExpression = KtPsiUtil.getLastElementDeparenthesized(expressionArgument.valueArgument.getArgumentExpression (), context.statementFilter)
|
||||||
@@ -143,7 +142,7 @@ class DiagnosticReporterByTrackingStrategy(
|
|||||||
|
|
||||||
private fun reportUnstableSmartCast(unstableSmartCast: UnstableSmartCast) {
|
private fun reportUnstableSmartCast(unstableSmartCast: UnstableSmartCast) {
|
||||||
// todo hack -- remove it after removing SmartCastManager
|
// todo hack -- remove it after removing SmartCastManager
|
||||||
reportSmartCast(SmartCastDiagnostic(unstableSmartCast.expressionArgument, unstableSmartCast.targetType))
|
reportSmartCast(SmartCastDiagnostic(unstableSmartCast.argument, unstableSmartCast.targetType))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun constraintError(diagnostic: KotlinCallDiagnostic) {
|
override fun constraintError(diagnostic: KotlinCallDiagnostic) {
|
||||||
|
|||||||
+2
-2
@@ -58,7 +58,7 @@ class AdditionalDiagnosticReporter {
|
|||||||
}
|
}
|
||||||
&&
|
&&
|
||||||
candidate.status.diagnostics.filterIsInstance<UnstableSmartCast>().none {
|
candidate.status.diagnostics.filterIsInstance<UnstableSmartCast>().none {
|
||||||
it.expressionArgument == receiver
|
it.argument == receiver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ class AdditionalDiagnosticReporter {
|
|||||||
val smartCastDiagnostic = createSmartCastDiagnostic(argument, argument.getExpectedType(parameter)) ?: continue
|
val smartCastDiagnostic = createSmartCastDiagnostic(argument, argument.getExpectedType(parameter)) ?: continue
|
||||||
|
|
||||||
val thereIsUnstableSmartCastError = candidate.status.diagnostics.filterIsInstance<UnstableSmartCast>().any {
|
val thereIsUnstableSmartCastError = candidate.status.diagnostics.filterIsInstance<UnstableSmartCast>().any {
|
||||||
it.expressionArgument == argument
|
it.argument == argument
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!thereIsUnstableSmartCastError) {
|
if (!thereIsUnstableSmartCastError) {
|
||||||
|
|||||||
+4
-66
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.*
|
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -153,6 +152,10 @@ class ArgumentsToParametersMapper {
|
|||||||
result[parameter.original] = ResolvedCallArgument.SimpleArgument(argument)
|
result[parameter.original] = ResolvedCallArgument.SimpleArgument(argument)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun ValueParameterDescriptor.getOverriddenParameterWithOtherName() = overriddenDescriptors.firstOrNull {
|
||||||
|
it.containingDeclaration.hasStableParameterNames() && it.name != name
|
||||||
|
}
|
||||||
|
|
||||||
private fun findParameterByName(argument: KotlinCallArgument, name: Name): ValueParameterDescriptor? {
|
private fun findParameterByName(argument: KotlinCallArgument, name: Name): ValueParameterDescriptor? {
|
||||||
val parameter = getParameterByName(name)
|
val parameter = getParameterByName(name)
|
||||||
|
|
||||||
@@ -258,71 +261,6 @@ class ArgumentsToParametersMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TooManyArguments(val argument: KotlinCallArgument, val descriptor: CallableDescriptor) :
|
|
||||||
KotlinCallDiagnostic(INAPPLICABLE) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class NonVarargSpread (val argument: KotlinCallArgument, val parameterDescriptor: ValueParameterDescriptor) :
|
|
||||||
KotlinCallDiagnostic(INAPPLICABLE) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgumentSpread(argument, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class MixingNamedAndPositionArguments(val argument: KotlinCallArgument) :
|
|
||||||
KotlinCallDiagnostic(INAPPLICABLE) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class NamedArgumentNotAllowed(val argument: KotlinCallArgument, val descriptor: CallableDescriptor) :
|
|
||||||
KotlinCallDiagnostic(INAPPLICABLE) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgumentName(argument, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class NameNotFound(val argument: KotlinCallArgument, val descriptor: CallableDescriptor) :
|
|
||||||
KotlinCallDiagnostic(INAPPLICABLE) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgumentName(argument, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class NoValueForParameter(val parameterDescriptor: ValueParameterDescriptor,
|
|
||||||
val descriptor: CallableDescriptor) :
|
|
||||||
KotlinCallDiagnostic(INAPPLICABLE) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCall(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class ArgumentPassedTwice(val argument: KotlinCallArgument,
|
|
||||||
val parameterDescriptor: ValueParameterDescriptor,
|
|
||||||
val firstOccurrence: ResolvedCallArgument) :
|
|
||||||
KotlinCallDiagnostic(INAPPLICABLE) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgumentName(argument, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class VarargArgumentOutsideParentheses(
|
|
||||||
val argument: KotlinCallArgument,
|
|
||||||
val parameterDescriptor: ValueParameterDescriptor) :
|
|
||||||
KotlinCallDiagnostic(INAPPLICABLE) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class NameForAmbiguousParameter(
|
|
||||||
val argument: KotlinCallArgument,
|
|
||||||
val parameterDescriptor: ValueParameterDescriptor,
|
|
||||||
val overriddenParameterWithOtherName: ValueParameterDescriptor
|
|
||||||
) : KotlinCallDiagnostic(CONVENTION_ERROR) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgumentName(argument, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class NamedArgumentReference(
|
|
||||||
val argument: KotlinCallArgument,
|
|
||||||
val parameterDescriptor: ValueParameterDescriptor
|
|
||||||
) : KotlinCallDiagnostic(RESOLVED) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgumentName(argument, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
val ValueParameterDescriptor.isVararg: Boolean get() = varargElementType != null
|
|
||||||
|
|
||||||
fun ValueParameterDescriptor.getOverriddenParameterWithOtherName() = overriddenDescriptors.firstOrNull {
|
|
||||||
it.containingDeclaration.hasStableParameterNames() && it.name != name
|
|
||||||
}
|
|
||||||
+2
-2
@@ -40,8 +40,6 @@ internal val ReceiverValueWithSmartCastInfo.stableType: UnwrappedType
|
|||||||
return intersectWrappedTypes(possibleTypes + receiverValue.type)
|
return intersectWrappedTypes(possibleTypes + receiverValue.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
internal fun KotlinCallArgument.getExpectedType(parameter: ValueParameterDescriptor) =
|
internal fun KotlinCallArgument.getExpectedType(parameter: ValueParameterDescriptor) =
|
||||||
if (this.isSpread) {
|
if (this.isSpread) {
|
||||||
parameter.type.unwrap()
|
parameter.type.unwrap()
|
||||||
@@ -49,3 +47,5 @@ internal fun KotlinCallArgument.getExpectedType(parameter: ValueParameterDescrip
|
|||||||
else {
|
else {
|
||||||
parameter.varargElementType?.unwrap() ?: parameter.type.unwrap()
|
parameter.varargElementType?.unwrap() ?: parameter.type.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val ValueParameterDescriptor.isVararg: Boolean get() = varargElementType != null
|
||||||
|
|||||||
+1
-16
@@ -52,6 +52,7 @@ sealed class CallableReceiver(val receiver: ReceiverValueWithSmartCastInfo) {
|
|||||||
class ExplicitValueReceiver(val lhsArgument: SimpleKotlinCallArgument, receiver: ReceiverValueWithSmartCastInfo) : CallableReceiver(receiver)
|
class ExplicitValueReceiver(val lhsArgument: SimpleKotlinCallArgument, receiver: ReceiverValueWithSmartCastInfo) : CallableReceiver(receiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo investigate similar code in CheckVisibility
|
||||||
private val CallableReceiver.asReceiverValueForVisibilityChecks: ReceiverValue
|
private val CallableReceiver.asReceiverValueForVisibilityChecks: ReceiverValue
|
||||||
get() = receiver.receiverValue
|
get() = receiver.receiverValue
|
||||||
|
|
||||||
@@ -323,19 +324,3 @@ class CallableReferencesCandidateFactory(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CallableReferenceNotCompatible(
|
|
||||||
val argument: CallableReferenceKotlinCallArgument,
|
|
||||||
val candidate: CallableMemberDescriptor,
|
|
||||||
val expectedType: UnwrappedType?,
|
|
||||||
val callableReverenceType: UnwrappedType
|
|
||||||
) : KotlinCallDiagnostic(ResolutionCandidateApplicability.INAPPLICABLE) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class NotCallableMemberReference(
|
|
||||||
val argument: CallableReferenceKotlinCallArgument,
|
|
||||||
val candidate: CallableDescriptor
|
|
||||||
) : KotlinCallDiagnostic(ResolutionCandidateApplicability.INAPPLICABLE) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
|
|
||||||
}
|
|
||||||
+17
-36
@@ -28,13 +28,10 @@ import org.jetbrains.kotlin.resolve.calls.inference.substitute
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCast
|
import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCast
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.*
|
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability
|
import org.jetbrains.kotlin.resolve.calls.tower.InfixCallNoInfixModifier
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.INAPPLICABLE
|
import org.jetbrains.kotlin.resolve.calls.tower.InvokeConventionCallNoOperatorModifier
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.RUNTIME_ERROR
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.VisibilityError
|
import org.jetbrains.kotlin.resolve.calls.tower.VisibilityError
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
|
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
|
||||||
import org.jetbrains.kotlin.types.TypeConstructor
|
|
||||||
import org.jetbrains.kotlin.types.UnwrappedType
|
|
||||||
import org.jetbrains.kotlin.utils.SmartList
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||||
|
|
||||||
@@ -252,38 +249,22 @@ internal object CheckArguments : ResolutionPart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object InstantiationOfAbstractClass : KotlinCallDiagnostic(RUNTIME_ERROR) {
|
internal object CheckInfixResolutionPart : ResolutionPart {
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCall(this)
|
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
||||||
|
if (kotlinCall.isInfixCall && (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isInfix)) {
|
||||||
|
return listOf(InfixCallNoInfixModifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SmartCastDiagnostic(val expressionArgument: ExpressionKotlinCallArgument, val smartCastType: UnwrappedType): KotlinCallDiagnostic(ResolutionCandidateApplicability.RESOLVED) {
|
internal object CheckOperatorResolutionPart : ResolutionPart {
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(expressionArgument, this)
|
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
||||||
}
|
if (kotlinCall.isOperatorCall && (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isOperator)) {
|
||||||
|
return listOf(InvokeConventionCallNoOperatorModifier)
|
||||||
|
}
|
||||||
|
|
||||||
class UnstableSmartCast(val expressionArgument: ExpressionKotlinCallArgument, val targetType: UnwrappedType) :
|
return emptyList()
|
||||||
KotlinCallDiagnostic(ResolutionCandidateApplicability.MAY_THROW_RUNTIME_ERROR) {
|
}
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(expressionArgument, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class UnsafeCallError(val receiver: SimpleKotlinCallArgument) : KotlinCallDiagnostic(ResolutionCandidateApplicability.MAY_THROW_RUNTIME_ERROR) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallReceiver(receiver, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class NoneCallableReferenceCandidates(val argument: CallableReferenceKotlinCallArgument) : KotlinCallDiagnostic(INAPPLICABLE) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class CallableReferenceCandidatesAmbiguity(
|
|
||||||
val argument: CallableReferenceKotlinCallArgument,
|
|
||||||
val candidates: Collection<CallableReferenceCandidate>
|
|
||||||
) : KotlinCallDiagnostic(INAPPLICABLE) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class NotCallableExpectedType(
|
|
||||||
val argument: CallableReferenceKotlinCallArgument,
|
|
||||||
val expectedType: UnwrappedType,
|
|
||||||
val notCallableTypeConstructor: TypeConstructor
|
|
||||||
) : KotlinCallDiagnostic(INAPPLICABLE) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
|
|
||||||
}
|
}
|
||||||
+1
-4
@@ -23,10 +23,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.addSubtypeConstraintIfCompat
|
|||||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ArgumentConstraintPosition
|
import org.jetbrains.kotlin.resolve.calls.inference.model.ArgumentConstraintPosition
|
||||||
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.ReceiverConstraintPosition
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ExpressionKotlinCallArgument
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.SimpleKotlinCallArgument
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.SubKotlinCallArgument
|
|
||||||
import org.jetbrains.kotlin.types.UnwrappedType
|
import org.jetbrains.kotlin.types.UnwrappedType
|
||||||
import org.jetbrains.kotlin.types.checker.captureFromExpression
|
import org.jetbrains.kotlin.types.checker.captureFromExpression
|
||||||
import org.jetbrains.kotlin.types.checker.hasSupertypeWithGivenTypeConstructor
|
import org.jetbrains.kotlin.types.checker.hasSupertypeWithGivenTypeConstructor
|
||||||
|
|||||||
-44
@@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.calls.components
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolutionPart
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.SimpleKotlinResolutionCandidate
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.InfixCallNoInfixModifier
|
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.InvokeConventionCallNoOperatorModifier
|
|
||||||
|
|
||||||
object CheckInfixResolutionPart : ResolutionPart {
|
|
||||||
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
|
||||||
if (kotlinCall.isInfixCall && (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isInfix)) {
|
|
||||||
return listOf(InfixCallNoInfixModifier)
|
|
||||||
}
|
|
||||||
|
|
||||||
return emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object CheckOperatorResolutionPart : ResolutionPart {
|
|
||||||
override fun SimpleKotlinResolutionCandidate.process(): List<KotlinCallDiagnostic> {
|
|
||||||
if (kotlinCall.isOperatorCall && (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isOperator)) {
|
|
||||||
return listOf(InvokeConventionCallNoOperatorModifier)
|
|
||||||
}
|
|
||||||
|
|
||||||
return emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-4
@@ -58,7 +58,3 @@ class TypeArgumentsToParametersMapper {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class WrongCountOfTypeArguments(val descriptor: CallableDescriptor, val currentCount: Int) :
|
|
||||||
KotlinCallDiagnostic(ResolutionCandidateApplicability.INAPPLICABLE) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.onTypeArguments(this)
|
|
||||||
}
|
|
||||||
|
|||||||
+15
-13
@@ -19,6 +19,8 @@ package org.jetbrains.kotlin.resolve.calls.inference.model
|
|||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||||
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability
|
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.INAPPLICABLE
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.UnwrappedType
|
import org.jetbrains.kotlin.types.UnwrappedType
|
||||||
|
|
||||||
@@ -61,20 +63,20 @@ class IncorporationConstraintPosition(val from: ConstraintPosition, val initialC
|
|||||||
@Deprecated("Should be used only in SimpleConstraintSystemImpl")
|
@Deprecated("Should be used only in SimpleConstraintSystemImpl")
|
||||||
object SimpleConstraintSystemConstraintPosition : ConstraintPosition()
|
object SimpleConstraintSystemConstraintPosition : ConstraintPosition()
|
||||||
|
|
||||||
|
abstract class ConstraintSystemCallDiagnostic(applicability: ResolutionCandidateApplicability) : KotlinCallDiagnostic(applicability) {
|
||||||
class NewConstraintError(val lowerType: UnwrappedType, val upperType: UnwrappedType, val position: IncorporationConstraintPosition) :
|
|
||||||
KotlinCallDiagnostic(
|
|
||||||
if (position.from is ReceiverConstraintPosition) ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER
|
|
||||||
else ResolutionCandidateApplicability.INAPPLICABLE
|
|
||||||
) {
|
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.constraintError(this)
|
override fun report(reporter: DiagnosticReporter) = reporter.constraintError(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
class CapturedTypeFromSubtyping(val typeVariable: NewTypeVariable, val constraintType: UnwrappedType, val position: ConstraintPosition) :
|
class NewConstraintError(
|
||||||
KotlinCallDiagnostic(ResolutionCandidateApplicability.INAPPLICABLE) {
|
val lowerType: UnwrappedType,
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.constraintError(this)
|
val upperType: UnwrappedType,
|
||||||
}
|
val position: IncorporationConstraintPosition
|
||||||
|
) : ConstraintSystemCallDiagnostic(if (position.from is ReceiverConstraintPosition) INAPPLICABLE_WRONG_RECEIVER else INAPPLICABLE)
|
||||||
|
|
||||||
class NotEnoughInformationForTypeParameter(val typeVariable: NewTypeVariable) : KotlinCallDiagnostic(ResolutionCandidateApplicability.INAPPLICABLE) {
|
class CapturedTypeFromSubtyping(
|
||||||
override fun report(reporter: DiagnosticReporter) = reporter.constraintError(this)
|
val typeVariable: NewTypeVariable,
|
||||||
}
|
val constraintType: UnwrappedType,
|
||||||
|
val position: ConstraintPosition
|
||||||
|
) : ConstraintSystemCallDiagnostic(INAPPLICABLE)
|
||||||
|
|
||||||
|
class NotEnoughInformationForTypeParameter(val typeVariable: NewTypeVariable) : ConstraintSystemCallDiagnostic(INAPPLICABLE)
|
||||||
+141
@@ -0,0 +1,141 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2017 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.resolve.calls.model
|
||||||
|
|
||||||
|
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.tower.ResolutionCandidateApplicability.*
|
||||||
|
import org.jetbrains.kotlin.types.TypeConstructor
|
||||||
|
import org.jetbrains.kotlin.types.UnwrappedType
|
||||||
|
|
||||||
|
abstract class InapplicableArgumentDiagnostic : KotlinCallDiagnostic(INAPPLICABLE) {
|
||||||
|
abstract val argument: KotlinCallArgument
|
||||||
|
|
||||||
|
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ArgumentsToParameterMapper
|
||||||
|
class TooManyArguments(override val argument: KotlinCallArgument, val descriptor: CallableDescriptor) : InapplicableArgumentDiagnostic()
|
||||||
|
|
||||||
|
class NonVarargSpread (val argument: KotlinCallArgument, val parameterDescriptor: ValueParameterDescriptor) : KotlinCallDiagnostic(INAPPLICABLE) {
|
||||||
|
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgumentSpread(argument, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class MixingNamedAndPositionArguments(override val argument: KotlinCallArgument) : InapplicableArgumentDiagnostic()
|
||||||
|
|
||||||
|
class NamedArgumentNotAllowed(val argument: KotlinCallArgument, val descriptor: CallableDescriptor) : KotlinCallDiagnostic(INAPPLICABLE) {
|
||||||
|
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgumentName(argument, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class NameNotFound(val argument: KotlinCallArgument, val descriptor: CallableDescriptor) : KotlinCallDiagnostic(INAPPLICABLE) {
|
||||||
|
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgumentName(argument, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class NoValueForParameter(
|
||||||
|
val parameterDescriptor: ValueParameterDescriptor,
|
||||||
|
val descriptor: CallableDescriptor
|
||||||
|
) : KotlinCallDiagnostic(INAPPLICABLE) {
|
||||||
|
override fun report(reporter: DiagnosticReporter) = reporter.onCall(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class ArgumentPassedTwice(
|
||||||
|
val argument: KotlinCallArgument,
|
||||||
|
val parameterDescriptor: ValueParameterDescriptor,
|
||||||
|
val firstOccurrence: ResolvedCallArgument
|
||||||
|
) : KotlinCallDiagnostic(INAPPLICABLE) {
|
||||||
|
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgumentName(argument, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class VarargArgumentOutsideParentheses(
|
||||||
|
override val argument: KotlinCallArgument,
|
||||||
|
val parameterDescriptor: ValueParameterDescriptor
|
||||||
|
) : InapplicableArgumentDiagnostic()
|
||||||
|
|
||||||
|
class NameForAmbiguousParameter(
|
||||||
|
val argument: KotlinCallArgument,
|
||||||
|
val parameterDescriptor: ValueParameterDescriptor,
|
||||||
|
val overriddenParameterWithOtherName: ValueParameterDescriptor
|
||||||
|
) : KotlinCallDiagnostic(CONVENTION_ERROR) {
|
||||||
|
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgumentName(argument, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class NamedArgumentReference(
|
||||||
|
val argument: KotlinCallArgument,
|
||||||
|
val parameterDescriptor: ValueParameterDescriptor
|
||||||
|
) : KotlinCallDiagnostic(RESOLVED) {
|
||||||
|
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgumentName(argument, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TypeArgumentsToParameterMapper
|
||||||
|
class WrongCountOfTypeArguments(
|
||||||
|
val descriptor: CallableDescriptor,
|
||||||
|
val currentCount: Int
|
||||||
|
) : KotlinCallDiagnostic(INAPPLICABLE) {
|
||||||
|
override fun report(reporter: DiagnosticReporter) = reporter.onTypeArguments(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Callable reference resolution
|
||||||
|
class CallableReferenceNotCompatible(
|
||||||
|
override val argument: CallableReferenceKotlinCallArgument,
|
||||||
|
val candidate: CallableMemberDescriptor,
|
||||||
|
val expectedType: UnwrappedType?,
|
||||||
|
val callableReverenceType: UnwrappedType
|
||||||
|
) : InapplicableArgumentDiagnostic()
|
||||||
|
|
||||||
|
class NotCallableMemberReference(
|
||||||
|
override val argument: CallableReferenceKotlinCallArgument,
|
||||||
|
val candidate: CallableDescriptor
|
||||||
|
) : InapplicableArgumentDiagnostic()
|
||||||
|
|
||||||
|
class NoneCallableReferenceCandidates(override val argument: CallableReferenceKotlinCallArgument) : InapplicableArgumentDiagnostic()
|
||||||
|
|
||||||
|
class CallableReferenceCandidatesAmbiguity(
|
||||||
|
override val argument: CallableReferenceKotlinCallArgument,
|
||||||
|
val candidates: Collection<CallableReferenceCandidate>
|
||||||
|
) : InapplicableArgumentDiagnostic()
|
||||||
|
|
||||||
|
class NotCallableExpectedType(
|
||||||
|
override val argument: CallableReferenceKotlinCallArgument,
|
||||||
|
val expectedType: UnwrappedType,
|
||||||
|
val notCallableTypeConstructor: TypeConstructor
|
||||||
|
) : InapplicableArgumentDiagnostic()
|
||||||
|
|
||||||
|
// SmartCasts
|
||||||
|
class SmartCastDiagnostic(
|
||||||
|
val argument: ExpressionKotlinCallArgument,
|
||||||
|
val smartCastType: UnwrappedType
|
||||||
|
): KotlinCallDiagnostic(RESOLVED) {
|
||||||
|
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class UnstableSmartCast(
|
||||||
|
val argument: ExpressionKotlinCallArgument,
|
||||||
|
val targetType: UnwrappedType
|
||||||
|
) : KotlinCallDiagnostic(MAY_THROW_RUNTIME_ERROR) {
|
||||||
|
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class UnsafeCallError(val receiver: SimpleKotlinCallArgument) : KotlinCallDiagnostic(MAY_THROW_RUNTIME_ERROR) {
|
||||||
|
override fun report(reporter: DiagnosticReporter) = reporter.onCallReceiver(receiver, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Other
|
||||||
|
object InstantiationOfAbstractClass : KotlinCallDiagnostic(RUNTIME_ERROR) {
|
||||||
|
override fun report(reporter: DiagnosticReporter) = reporter.onCall(this)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user