diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt index cca8f68aed8..c0e05acd658 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -23,7 +23,6 @@ import org.jetbrains.kotlin.diagnostics.Errors.BadNamedArgumentsTarget.* import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext 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.inference.model.* import org.jetbrains.kotlin.resolve.calls.model.* @@ -123,7 +122,7 @@ class DiagnosticReporterByTrackingStrategy( } private fun reportSmartCast(smartCastDiagnostic: SmartCastDiagnostic) { - val expressionArgument = smartCastDiagnostic.expressionArgument + val expressionArgument = smartCastDiagnostic.argument if (expressionArgument is ExpressionKotlinCallArgumentImpl) { val context = context.replaceDataFlowInfo(expressionArgument.dataFlowInfoBeforeThisArgument) val argumentExpression = KtPsiUtil.getLastElementDeparenthesized(expressionArgument.valueArgument.getArgumentExpression (), context.statementFilter) @@ -143,7 +142,7 @@ class DiagnosticReporterByTrackingStrategy( private fun reportUnstableSmartCast(unstableSmartCast: UnstableSmartCast) { // todo hack -- remove it after removing SmartCastManager - reportSmartCast(SmartCastDiagnostic(unstableSmartCast.expressionArgument, unstableSmartCast.targetType)) + reportSmartCast(SmartCastDiagnostic(unstableSmartCast.argument, unstableSmartCast.targetType)) } override fun constraintError(diagnostic: KotlinCallDiagnostic) { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/AdditionalDiagnosticReporter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/AdditionalDiagnosticReporter.kt index f01c225c03f..acb41ffd0e3 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/AdditionalDiagnosticReporter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/AdditionalDiagnosticReporter.kt @@ -58,7 +58,7 @@ class AdditionalDiagnosticReporter { } && candidate.status.diagnostics.filterIsInstance().none { - it.expressionArgument == receiver + it.argument == receiver } } } @@ -73,7 +73,7 @@ class AdditionalDiagnosticReporter { val smartCastDiagnostic = createSmartCastDiagnostic(argument, argument.getExpectedType(parameter)) ?: continue val thereIsUnstableSmartCastError = candidate.status.diagnostics.filterIsInstance().any { - it.expressionArgument == argument + it.argument == argument } if (!thereIsUnstableSmartCastError) { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ArgumentsToParametersMapper.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ArgumentsToParametersMapper.kt index 7e0b14a621e..f0b02d9bd78 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ArgumentsToParametersMapper.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ArgumentsToParametersMapper.kt @@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.calls.model.* -import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.* import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue import java.util.* @@ -153,6 +152,10 @@ class ArgumentsToParametersMapper { 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? { 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 -} \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ArgumentsUtils.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ArgumentsUtils.kt index c2d5137ad59..fb3f05d11fb 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ArgumentsUtils.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ArgumentsUtils.kt @@ -40,12 +40,12 @@ internal val ReceiverValueWithSmartCastInfo.stableType: UnwrappedType return intersectWrappedTypes(possibleTypes + receiverValue.type) } - - internal fun KotlinCallArgument.getExpectedType(parameter: ValueParameterDescriptor) = if (this.isSpread) { parameter.type.unwrap() } else { parameter.varargElementType?.unwrap() ?: parameter.type.unwrap() - } \ No newline at end of file + } + +val ValueParameterDescriptor.isVararg: Boolean get() = varargElementType != null diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt index 2ef9822aee2..e5efcfee3d6 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolution.kt @@ -52,6 +52,7 @@ sealed class CallableReceiver(val receiver: ReceiverValueWithSmartCastInfo) { class ExplicitValueReceiver(val lhsArgument: SimpleKotlinCallArgument, receiver: ReceiverValueWithSmartCastInfo) : CallableReceiver(receiver) } +// todo investigate similar code in CheckVisibility private val CallableReceiver.asReceiverValueForVisibilityChecks: 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) -} \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index 320f3d6836d..aaef8f0b36e 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -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.smartcasts.getReceiverValueWithSmartCast import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind.* -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.RUNTIME_ERROR +import org.jetbrains.kotlin.resolve.calls.tower.InfixCallNoInfixModifier +import org.jetbrains.kotlin.resolve.calls.tower.InvokeConventionCallNoOperatorModifier import org.jetbrains.kotlin.resolve.calls.tower.VisibilityError 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.addIfNotNull @@ -252,38 +249,22 @@ internal object CheckArguments : ResolutionPart { } } -object InstantiationOfAbstractClass : KotlinCallDiagnostic(RUNTIME_ERROR) { - override fun report(reporter: DiagnosticReporter) = reporter.onCall(this) +internal object CheckInfixResolutionPart : ResolutionPart { + override fun SimpleKotlinResolutionCandidate.process(): List { + if (kotlinCall.isInfixCall && (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isInfix)) { + return listOf(InfixCallNoInfixModifier) + } + + return emptyList() + } } -class SmartCastDiagnostic(val expressionArgument: ExpressionKotlinCallArgument, val smartCastType: UnwrappedType): KotlinCallDiagnostic(ResolutionCandidateApplicability.RESOLVED) { - override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(expressionArgument, this) -} +internal object CheckOperatorResolutionPart : ResolutionPart { + override fun SimpleKotlinResolutionCandidate.process(): List { + if (kotlinCall.isOperatorCall && (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isOperator)) { + return listOf(InvokeConventionCallNoOperatorModifier) + } -class UnstableSmartCast(val expressionArgument: ExpressionKotlinCallArgument, val targetType: UnwrappedType) : - 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 -) : 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) + return emptyList() + } } \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SimpleArgumentsChecks.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SimpleArgumentsChecks.kt index f8197b1587d..a7e8ce224a0 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SimpleArgumentsChecks.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SimpleArgumentsChecks.kt @@ -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.ConstraintPosition import org.jetbrains.kotlin.resolve.calls.inference.model.ReceiverConstraintPosition -import org.jetbrains.kotlin.resolve.calls.model.ExpressionKotlinCallArgument -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.resolve.calls.model.* import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.types.checker.captureFromExpression import org.jetbrains.kotlin.types.checker.hasSupertypeWithGivenTypeConstructor diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SpecialResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SpecialResolutionParts.kt deleted file mode 100644 index 0ddfc097b8f..00000000000 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SpecialResolutionParts.kt +++ /dev/null @@ -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 { - if (kotlinCall.isInfixCall && (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isInfix)) { - return listOf(InfixCallNoInfixModifier) - } - - return emptyList() - } -} - -object CheckOperatorResolutionPart : ResolutionPart { - override fun SimpleKotlinResolutionCandidate.process(): List { - if (kotlinCall.isOperatorCall && (candidateDescriptor !is FunctionDescriptor || !candidateDescriptor.isOperator)) { - return listOf(InvokeConventionCallNoOperatorModifier) - } - - return emptyList() - } -} \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/TypeArgumentsToParametersMapper.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/TypeArgumentsToParametersMapper.kt index c9d92e0ca28..e4edfdc5aa6 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/TypeArgumentsToParametersMapper.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/TypeArgumentsToParametersMapper.kt @@ -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) -} diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt index 4d06587fe3e..ce4b4d5dd4d 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrors.kt @@ -19,6 +19,8 @@ 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.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.UnwrappedType @@ -61,20 +63,20 @@ class IncorporationConstraintPosition(val from: ConstraintPosition, val initialC @Deprecated("Should be used only in SimpleConstraintSystemImpl") object SimpleConstraintSystemConstraintPosition : ConstraintPosition() - -class NewConstraintError(val lowerType: UnwrappedType, val upperType: UnwrappedType, val position: IncorporationConstraintPosition) : - KotlinCallDiagnostic( - if (position.from is ReceiverConstraintPosition) ResolutionCandidateApplicability.INAPPLICABLE_WRONG_RECEIVER - else ResolutionCandidateApplicability.INAPPLICABLE - ) { +abstract class ConstraintSystemCallDiagnostic(applicability: ResolutionCandidateApplicability) : KotlinCallDiagnostic(applicability) { override fun report(reporter: DiagnosticReporter) = reporter.constraintError(this) } -class CapturedTypeFromSubtyping(val typeVariable: NewTypeVariable, val constraintType: UnwrappedType, val position: ConstraintPosition) : - KotlinCallDiagnostic(ResolutionCandidateApplicability.INAPPLICABLE) { - override fun report(reporter: DiagnosticReporter) = reporter.constraintError(this) -} +class NewConstraintError( + val lowerType: UnwrappedType, + 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) { - override fun report(reporter: DiagnosticReporter) = reporter.constraintError(this) -} \ No newline at end of file +class CapturedTypeFromSubtyping( + val typeVariable: NewTypeVariable, + val constraintType: UnwrappedType, + val position: ConstraintPosition +) : ConstraintSystemCallDiagnostic(INAPPLICABLE) + +class NotEnoughInformationForTypeParameter(val typeVariable: NewTypeVariable) : ConstraintSystemCallDiagnostic(INAPPLICABLE) \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnistics.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnistics.kt new file mode 100644 index 00000000000..916c32d9f2d --- /dev/null +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnistics.kt @@ -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 +) : 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) +}