diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt index a0f6cbe8f6e..2fd5855f2f5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionCallbacksImpl.kt @@ -120,6 +120,7 @@ class KotlinResolutionCallbacksImpl( val lastExpressionArgument = getLastDeparentesizedExpression(psiCallArgument)?.let { lastExpression -> if (expectedReturnType?.isUnit() == true) return@let null // coercion to Unit + // todo lastExpression can be if without else val lastExpressionType = trace.getType(lastExpression) val lastExpressionTypeInfo = KotlinTypeInfo(lastExpressionType, lambdaInfo.dataFlowInfoAfter ?: functionTypeInfo.dataFlowInfo) createCallArgument(lastExpression, lastExpressionTypeInfo) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt index 96c5a3b917f..c7c45d1e044 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt @@ -70,6 +70,7 @@ class KotlinToResolvedCallTransformer( allResolvedCalls.add(result) if (trace != null) { + // todo: check checkers order val callCheckerContext = CallCheckerContext(context.replaceBindingTrace(trace), languageFeatureSettings) for (resolvedCall in allResolvedCalls) { runCallCheckers(resolvedCall, callCheckerContext) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt index 4843b961f9e..cc42e9b2cbb 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewCallArguments.kt @@ -221,7 +221,7 @@ internal fun createSimplePSICallArgument( // we should use DFI after this argument, because there can be some useful smartcast. Popular case: if branches. val receiverToCast = transformToReceiverWithSmartCastInfo( ownerDescriptor, bindingContext, - typeInfoForArgument.dataFlowInfo, + typeInfoForArgument.dataFlowInfo, // dataFlowInfoBeforeThisArgument cannot be used here, because of if() { if (x != null) return; x } ExpressionReceiver.create(ktExpression, baseType, bindingContext) ).prepareReceiverRegardingCaptureTypes() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt index c42a663c96c..3318c527886 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt @@ -108,7 +108,7 @@ class NewResolutionOldInference( ): ScopeTowerProcessor { val functionFactory = outer.CandidateFactoryImpl(name, context, tracing) val variableFactory = outer.CandidateFactoryImpl(name, context, tracing) - return CompositeScopeTowerProcessor( + return PrioritizedCompositeScopeTowerProcessor( createSimpleFunctionProcessor(scopeTower, name, functionFactory, explicitReceiver, classValueReceiver = false), createVariableProcessor(scopeTower, name, variableFactory, explicitReceiver, classValueReceiver = false) ) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt index bb339fcd6d2..8ee6ebeac74 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/PSICallResolver.kt @@ -531,14 +531,14 @@ class PSICallResolver( LHSResult.Object(ClassQualifier(calleeExpression, classifier)) } else { - LHSResult.Empty // this is error case actually + LHSResult.Error } } else { val fakeArgument = FakeValueArgumentForLeftCallableReference(ktExpression) val kotlinCallArgument = createSimplePSICallArgument(context, fakeArgument, lhsResult.typeInfo) - kotlinCallArgument?.let { LHSResult.Expression(it as SimpleKotlinCallArgument) } ?: LHSResult.Empty + kotlinCallArgument?.let { LHSResult.Expression(it as SimpleKotlinCallArgument) } ?: LHSResult.Error } } is DoubleColonLHS.Type -> { @@ -547,7 +547,7 @@ class PSICallResolver( LHSResult.Type(qualifier, lhsResult.type.unwrap()) } else { - LHSResult.Empty // this is error case actually + LHSResult.Error } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java index b6a9cc5f973..542ef78086c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/ExpressionTypingServices.java @@ -318,7 +318,6 @@ public class ExpressionTypingServices { ContextDependency dependency = context.contextDependency; if (KotlinResolutionConfigurationKt.getUSE_NEW_INFERENCE()) { dependency = ContextDependency.INDEPENDENT; - } return blockLevelVisitor.getTypeInfo(statementExpression, context.replaceExpectedType(expectedType).replaceContextDependency(dependency), true); 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 ea2bc6ab9f3..0232530dbc5 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 @@ -35,13 +35,10 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.DetailedReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.QualifierReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo -import org.jetbrains.kotlin.types.ErrorUtils -import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.UnwrappedType +import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.expressions.CoercionStrategy import org.jetbrains.kotlin.types.typeUtil.immediateSupertypes import org.jetbrains.kotlin.types.typeUtil.isUnit -import org.jetbrains.kotlin.types.upperIfFlexible import org.jetbrains.kotlin.utils.SmartList import org.jetbrains.kotlin.utils.addIfNotNull @@ -87,7 +84,7 @@ class CallableReferenceCandidate( fun createCallableReferenceProcessor(factory: CallableReferencesCandidateFactory): ScopeTowerProcessor { val lhsResult = factory.argument.lhsResult when (lhsResult) { - LHSResult.Empty, is LHSResult.Expression -> { + LHSResult.Empty, LHSResult.Error, is LHSResult.Expression -> { val explicitReceiver = (lhsResult as? LHSResult.Expression)?.lshCallArgument?.receiver return factory.createCallableProcessor(explicitReceiver) } @@ -95,18 +92,18 @@ fun createCallableReferenceProcessor(factory: CallableReferencesCandidateFactory val static = factory.createCallableProcessor(lhsResult.qualifier) val unbound = factory.createCallableProcessor(lhsResult.unboundDetailedReceiver) - // note that if we use CompositeScopeTowerProcessor then static will win over unbound members - val staticOrUnbound = CompositeSimpleScopeTowerProcessor(static, unbound) + // note that if we use PrioritizedCompositeScopeTowerProcessor then static will win over unbound members + val staticOrUnbound = SamePriorityCompositeScopeTowerProcessor(static, unbound) val asValue = lhsResult.qualifier.classValueReceiverWithSmartCastInfo ?: return staticOrUnbound - return CompositeScopeTowerProcessor(staticOrUnbound, factory.createCallableProcessor(asValue)) + return PrioritizedCompositeScopeTowerProcessor(staticOrUnbound, factory.createCallableProcessor(asValue)) } is LHSResult.Object -> { // callable reference to nested class constructor val static = factory.createCallableProcessor(lhsResult.qualifier) val boundObjectReference = factory.createCallableProcessor(lhsResult.objectValueReceiver) - return CompositeSimpleScopeTowerProcessor(static, boundObjectReference) + return SamePriorityCompositeScopeTowerProcessor(static, boundObjectReference) } } } @@ -120,33 +117,37 @@ fun ConstraintSystemOperation.checkCallableReference( expectedType: UnwrappedType?, ownerDescriptor: DeclarationDescriptor ): Pair { - val invisibleMember = Visibilities.findInvisibleMember(dispatchReceiver?.asReceiverValueForVisibilityChecks, - candidateDescriptor, ownerDescriptor) - val position = ArgumentConstraintPosition(argument) - val toFreshSubstitutor = createToFreshVariableSubstitutorAndAddInitialConstraints(candidateDescriptor, this, kotlinCall = null) - val reflectionType = toFreshSubstitutor.safeSubstitute(reflectionCandidateType) + val toFreshSubstitutor = createToFreshVariableSubstitutorAndAddInitialConstraints(candidateDescriptor, this) if (expectedType != null) { - addSubtypeConstraint(reflectionType, expectedType, position) + addSubtypeConstraint(toFreshSubstitutor.safeSubstitute(reflectionCandidateType), expectedType, position) } addReceiverConstraint(toFreshSubstitutor, dispatchReceiver, candidateDescriptor.dispatchReceiverParameter, position) addReceiverConstraint(toFreshSubstitutor, extensionReceiver, candidateDescriptor.extensionReceiverParameter, position) + val invisibleMember = Visibilities.findInvisibleMember(dispatchReceiver?.asReceiverValueForVisibilityChecks, + candidateDescriptor, ownerDescriptor) return toFreshSubstitutor to invisibleMember?.let(::VisibilityError) } private fun ConstraintSystemOperation.addReceiverConstraint( toFreshSubstitutor: FreshVariableNewTypeSubstitutor, - receiver: CallableReceiver?, - candidateReceiver: ReceiverParameterDescriptor?, + receiverArgument: CallableReceiver?, + receiverParameter: ReceiverParameterDescriptor?, position: ArgumentConstraintPosition ) { - val expectedType = toFreshSubstitutor.safeSubstitute(candidateReceiver?.value?.type?.unwrap() ?: return) - val receiverType = receiver?.receiver?.stableType ?: return + if (receiverArgument == null || receiverParameter == null) { + assert(receiverArgument == null) { "Receiver argument should be null if parameter is: $receiverArgument" } + assert(receiverParameter == null) { "Receiver parameter should be null if argument is: $receiverParameter" } + return + } + + val expectedType = toFreshSubstitutor.safeSubstitute(receiverParameter.value.type.unwrap()) + val receiverType = receiverArgument.receiver.stableType addSubtypeConstraint(receiverType, expectedType, position) } @@ -170,11 +171,17 @@ class CallableReferencesCandidateFactory( val dispatchCallableReceiver = towerCandidate.dispatchReceiver?.let { toCallableReceiver(it, explicitReceiverKind == DISPATCH_RECEIVER) } val extensionCallableReceiver = extensionReceiver?.let { toCallableReceiver(it, explicitReceiverKind == EXTENSION_RECEIVER) } val candidateDescriptor = towerCandidate.descriptor + val diagnostics = SmartList() - val (reflectionCandidateType, defaults) = buildReflectionType(candidateDescriptor, - dispatchCallableReceiver, - extensionCallableReceiver, - expectedType) + val (reflectionCandidateType, defaults) = buildReflectionType( + candidateDescriptor, + dispatchCallableReceiver, + extensionCallableReceiver, + expectedType) + + if (defaults != 0) { + diagnostics.add(CallableReferencesDefaultArgumentUsed(argument, candidateDescriptor, defaults)) + } if (candidateDescriptor !is CallableMemberDescriptor) { val status = ResolutionCandidateStatus(listOf(NotCallableMemberReference(argument, candidateDescriptor))) @@ -182,15 +189,15 @@ class CallableReferencesCandidateFactory( explicitReceiverKind, reflectionCandidateType, defaults, status) } - val diagnostics = SmartList() diagnostics.addAll(towerCandidate.diagnostics) // todo smartcast on receiver diagnostic and CheckInstantiationOfAbstractClass compatibilityChecker { if (it.hasContradiction) return@compatibilityChecker - val (_, visibilityError) = it.checkCallableReference(argument, dispatchCallableReceiver, extensionCallableReceiver, candidateDescriptor, - reflectionCandidateType, expectedType, scopeTower.lexicalScope.ownerDescriptor) + val (_, visibilityError) = it.checkCallableReference( + argument, dispatchCallableReceiver, extensionCallableReceiver, candidateDescriptor, + reflectionCandidateType, expectedType, scopeTower.lexicalScope.ownerDescriptor) diagnostics.addIfNotNull(visibilityError) @@ -244,8 +251,10 @@ class CallableReferencesCandidateFactory( } if (mappedArguments.any { it == null }) return null - val unitExpectedType = functionType.let(KotlinType::getReturnTypeFromFunctionType).takeIf { it.upperIfFlexible().isUnit() } - val coercion = if (unitExpectedType != null) CoercionStrategy.COERCION_TO_UNIT else CoercionStrategy.NO_COERCION + // lower(Unit!) = Unit + val returnExpectedType = functionType.getReturnTypeFromFunctionType().lowerIfFlexible() + + val coercion = if (returnExpectedType.isUnit()) CoercionStrategy.COERCION_TO_UNIT else CoercionStrategy.NO_COERCION @Suppress("UNCHECKED_CAST") return Triple(mappedArguments as Array, coercion, defaults) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt index 221d40ae6a5..7ce5c9c64ef 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/CallableReferenceResolver.kt @@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator import org.jetbrains.kotlin.resolve.calls.tower.ImplicitScopeTower import org.jetbrains.kotlin.resolve.calls.tower.TowerResolver import org.jetbrains.kotlin.types.UnwrappedType +import org.jetbrains.kotlin.utils.addToStdlib.safeAs class CallableReferenceOverloadConflictResolver( @@ -68,11 +69,11 @@ class CallableReferenceResolver( val argument = postponedArgument.argument val expectedType = postponedArgument.expectedType - val subLHSCall = ((argument.lhsResult as? LHSResult.Expression)?.lshCallArgument as? SubKotlinCallArgument) + val subLHSCall = argument.lhsResult.safeAs()?.lshCallArgument.safeAs() if (subLHSCall != null) { csBuilder.addInnerCall(subLHSCall.resolvedCall) } - val candidates = runRLSResolution(scopeTower, argument, expectedType) { checkCallableReference -> + val candidates = runRHSResolution(scopeTower, argument, expectedType) { checkCallableReference -> csBuilder.runTransaction { checkCallableReference(this); false } } val chosenCandidate = when (candidates.size) { @@ -93,18 +94,20 @@ class CallableReferenceResolver( } - private fun runRLSResolution( + private fun runRHSResolution( scopeTower: ImplicitScopeTower, callableReference: CallableReferenceKotlinCallArgument, expectedType: UnwrappedType?, // this type can have not fixed type variable inside - compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit // you can run anything throw this operation and all this operation will be roll backed + compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit // you can run anything throw this operation and all this operation will be rolled back ): Set { val factory = CallableReferencesCandidateFactory(callableReference, callComponents, scopeTower, compatibilityChecker, expectedType) val processor = createCallableReferenceProcessor(factory) val candidates = towerResolver.runResolve(scopeTower, processor, useOrder = true) - return callableReferenceOverloadConflictResolver.chooseMaximallySpecificCandidates(candidates, CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, - discriminateGenerics = false, - isDebuggerContext = scopeTower.isDebuggerContext) + return callableReferenceOverloadConflictResolver.chooseMaximallySpecificCandidates( + candidates, + CheckArgumentTypesMode.CHECK_VALUE_ARGUMENTS, + discriminateGenerics = false, // we can't specify generics explicitly for callable references + isDebuggerContext = scopeTower.isDebuggerContext) } } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt index 812acbea6fb..1c9a0d2c997 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableForLambdaR import org.jetbrains.kotlin.resolve.calls.model.* import org.jetbrains.kotlin.types.UnwrappedType import org.jetbrains.kotlin.types.typeUtil.builtIns +import org.jetbrains.kotlin.utils.addToStdlib.safeAs fun createPostponedArgumentAndPerformInitialChecks( csBuilder: ConstraintSystemBuilder, @@ -60,20 +61,20 @@ private fun preprocessLambdaArgument( if (argument.parametersTypes != null) { parameters = argument.parametersTypes!!.mapIndexed { index, type -> - type ?: expectedParameters.getOrNull(index)?.type?.unwrap() ?: builtIns.anyType + type ?: expectedParameters.getOrNull(index)?.type?.unwrap() ?: builtIns.nullableAnyType } } else { // lambda without explicit parameters: { } parameters = expectedParameters.map { it.type.unwrap() } } - returnType = (argument as? FunctionExpression)?.returnType ?: expectedType.getReturnTypeFromFunctionType().unwrap() + returnType = argument.safeAs()?.returnType ?: expectedType.getReturnTypeFromFunctionType().unwrap() } else { val isFunctionSupertype = KotlinBuiltIns.isNotNullOrNullableFunctionSupertype(expectedType) - receiverType = (argument as? FunctionExpression)?.receiverType + receiverType = argument.safeAs()?.receiverType parameters = argument.parametersTypes?.map { it ?: builtIns.nothingType } ?: emptyList() - returnType = (argument as? FunctionExpression)?.returnType ?: + returnType = argument.safeAs()?.returnType ?: expectedType.arguments.singleOrNull()?.type?.unwrap()?.takeIf { isFunctionSupertype } ?: createFreshTypeVariableForLambdaReturnType(csBuilder, argument, builtIns) 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 a19575623f0..3c839e0390b 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 @@ -109,7 +109,7 @@ internal object CreateDescriptorWithFreshTypeVariables : ResolutionPart { descriptorWithFreshTypes = candidateDescriptor return emptyList() } - val toFreshVariables = createToFreshVariableSubstitutorAndAddInitialConstraints(candidateDescriptor, csBuilder, kotlinCall) + val toFreshVariables = createToFreshVariableSubstitutorAndAddInitialConstraints(candidateDescriptor, csBuilder) typeVariablesForFreshTypeParameters = toFreshVariables.freshVariables // bad function -- error on declaration side @@ -164,12 +164,11 @@ internal object CreateDescriptorWithFreshTypeVariables : ResolutionPart { fun createToFreshVariableSubstitutorAndAddInitialConstraints( candidateDescriptor: CallableDescriptor, - csBuilder: ConstraintSystemOperation, - kotlinCall: KotlinCall? + csBuilder: ConstraintSystemOperation ): FreshVariableNewTypeSubstitutor { val typeParameters = candidateDescriptor.typeParameters - val freshTypeVariables = typeParameters.map { TypeVariableFromCallableDescriptor(it, kotlinCall) } + val freshTypeVariables = typeParameters.map { TypeVariableFromCallableDescriptor(it) } val toFreshVariables = FreshVariableNewTypeSubstitutor(freshTypeVariables) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/TypeVariable.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/TypeVariable.kt index 0b90785f4d7..575abd9706f 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/TypeVariable.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/TypeVariable.kt @@ -20,11 +20,12 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.resolve.calls.model.KotlinCall import org.jetbrains.kotlin.resolve.calls.model.LambdaKotlinCallArgument import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns -import org.jetbrains.kotlin.resolve.scopes.MemberScope -import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.types.KotlinTypeFactory +import org.jetbrains.kotlin.types.SimpleType +import org.jetbrains.kotlin.types.TypeConstructor import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor @@ -53,8 +54,7 @@ sealed class NewTypeVariable(builtIns: KotlinBuiltIns, name: String) { } class TypeVariableFromCallableDescriptor( - val originalTypeParameter: TypeParameterDescriptor, - val call: KotlinCall? = null + val originalTypeParameter: TypeParameterDescriptor ) : NewTypeVariable(originalTypeParameter.builtIns, originalTypeParameter.name.identifier) class TypeVariableForLambdaReturnType( diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallArguments.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallArguments.kt index 778d8d1f542..5fdaf63588d 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallArguments.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallArguments.kt @@ -110,6 +110,8 @@ sealed class LHSResult { // todo this case is forbid for now object Empty: LHSResult() + + object Error: LHSResult() } interface CallableReferenceKotlinCallArgument : PostponableKotlinCallArgument { 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 index 17ead7fdc52..fbb7d4a5f63 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnistics.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnistics.kt @@ -98,6 +98,15 @@ class CallableReferenceNotCompatible( val callableReverenceType: UnwrappedType ) : InapplicableArgumentDiagnostic() +// supported by FE but not supported by BE now +class CallableReferencesDefaultArgumentUsed( + val argument: CallableReferenceKotlinCallArgument, + val candidate: CallableDescriptor, + val defaultsCount: Int +) : KotlinCallDiagnostic(IMPOSSIBLE_TO_GENERATE) { + override fun report(reporter: DiagnosticReporter) = reporter.onCallArgument(argument, this) +} + class NotCallableMemberReference( override val argument: CallableReferenceKotlinCallArgument, val candidate: CallableDescriptor diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt index afcb08f68cb..068f0753c28 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/results/OverloadingConflictResolver.kt @@ -38,7 +38,7 @@ open class OverloadingConflictResolver( private val getResultingDescriptor: (C) -> CallableDescriptor, private val createEmptyConstraintSystem: () -> SimpleConstraintSystem, private val createFlatSignature: (C) -> FlatSignature, - private val getVariableCandidates: (C) -> C?, // vor variable WithInvoke + private val getVariableCandidates: (C) -> C?, // for variable WithInvoke private val isFromSources: (CallableDescriptor) -> Boolean ) { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt index 2ac6288728b..ac68d186966 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/InvokeProcessors.kt @@ -17,8 +17,6 @@ package org.jetbrains.kotlin.resolve.calls.tower import org.jetbrains.kotlin.builtins.isBuiltinExtensionFunctionalType -import org.jetbrains.kotlin.descriptors.FunctionDescriptor -import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.calls.tasks.createSynthesizedInvokes @@ -182,7 +180,7 @@ fun createCallTowerProcessorForExplicitInvoke( usualInvoke } else { - CompositeScopeTowerProcessor( + PrioritizedCompositeScopeTowerProcessor( usualInvoke, InvokeExtensionScopeTowerProcessor(functionContext, invokeExtensionDescriptor, explicitReceiver = null) ) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ScopeTowerProcessors.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ScopeTowerProcessors.kt index ab90436e1be..bc633033abd 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ScopeTowerProcessors.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ScopeTowerProcessors.kt @@ -32,14 +32,14 @@ class KnownResultProcessor( } // use this if processors priority is important -class CompositeScopeTowerProcessor( +class PrioritizedCompositeScopeTowerProcessor( vararg val processors: ScopeTowerProcessor ) : ScopeTowerProcessor { override fun process(data: TowerData): List> = processors.flatMap { it.process(data) } } // use this if all processors has same priority -class CompositeSimpleScopeTowerProcessor( +class SamePriorityCompositeScopeTowerProcessor( private vararg val processors: SimpleScopeTowerProcessor ): SimpleScopeTowerProcessor { override fun simpleProcess(data: TowerData): Collection = processors.flatMap { it.simpleProcess(data) } @@ -192,7 +192,7 @@ private fun createSimpleProcessor( if (classValueReceiver && explicitReceiver is QualifierReceiver) { val classValue = explicitReceiver.classValueReceiverWithSmartCastInfo ?: return withoutClassValueProcessor - return CompositeScopeTowerProcessor( + return PrioritizedCompositeScopeTowerProcessor( withoutClassValueProcessor, ExplicitReceiverScopeTowerProcessor(scopeTower, context, classValue, collectCandidates) ) @@ -200,11 +200,14 @@ private fun createSimpleProcessor( return withoutClassValueProcessor } -fun createCallableReferenceProcessor(scopeTower: ImplicitScopeTower, name: Name, context: CandidateFactory, - explicitReceiver: DetailedReceiver?): SimpleScopeTowerProcessor { +fun createCallableReferenceProcessor( + scopeTower: ImplicitScopeTower, + name: Name, context: CandidateFactory, + explicitReceiver: DetailedReceiver? +): SimpleScopeTowerProcessor { val variable = createSimpleProcessorWithoutClassValueReceiver(scopeTower, context, explicitReceiver) { getVariables(name, it) } val function = createSimpleProcessorWithoutClassValueReceiver(scopeTower, context, explicitReceiver) { getFunctions(name, it) } - return CompositeSimpleScopeTowerProcessor(variable, function) + return SamePriorityCompositeScopeTowerProcessor(variable, function) } fun createVariableProcessor(scopeTower: ImplicitScopeTower, name: Name, @@ -213,7 +216,7 @@ fun createVariableProcessor(scopeTower: ImplicitScopeTower, name fun createVariableAndObjectProcessor(scopeTower: ImplicitScopeTower, name: Name, context: CandidateFactory, explicitReceiver: DetailedReceiver?, classValueReceiver: Boolean = true -) = CompositeScopeTowerProcessor( +) = PrioritizedCompositeScopeTowerProcessor( createVariableProcessor(scopeTower, name, context, explicitReceiver), createSimpleProcessor(scopeTower, context, explicitReceiver, classValueReceiver) { getObjects(name, it) } ) @@ -229,7 +232,7 @@ fun <С: Candidate> createFunctionProcessor( simpleContext: CandidateFactory<С>, factoryProviderForInvoke: CandidateFactoryProviderForInvoke<С>, explicitReceiver: DetailedReceiver? -): CompositeScopeTowerProcessor<С> { +): PrioritizedCompositeScopeTowerProcessor<С> { // a.foo() -- simple function call val simpleFunction = createSimpleFunctionProcessor(scopeTower, name, simpleContext, explicitReceiver) @@ -242,7 +245,7 @@ fun <С: Candidate> createFunctionProcessor( InvokeExtensionTowerProcessor(scopeTower, name, factoryProviderForInvoke, it) } - return CompositeScopeTowerProcessor(simpleFunction, invokeProcessor, invokeExtensionProcessor) + return PrioritizedCompositeScopeTowerProcessor(simpleFunction, invokeProcessor, invokeExtensionProcessor) } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt b/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt index 30f52eb8adf..61bce7f1da4 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt @@ -132,9 +132,9 @@ class TypeApproximator { if (conf.flexible) { /** - * Let inputTypes = L_1..U_1; resultType = L_2..U_2 - * We should create resultType such as inputTypes <: resultType. - * It means that if A <: inputTypes, then A <: U_1. And, because inputTypes <: resultType, + * Let inputType = L_1..U_1; resultType = L_2..U_2 + * We should create resultType such as inputType <: resultType. + * It means that if A <: inputType, then A <: U_1. And, because inputType <: resultType, * A <: resultType => A <: U_2. I.e. for every type A such A <: U_1, A <: U_2 => U_1 <: U_2. * * Similar for L_1 <: L_2: Let B : resultType <: B. L_2 <: B and L_1 <: B. @@ -147,7 +147,7 @@ class TypeApproximator { /** * If C <: L..U then C <: L. - * inputTypes.lower <: lowerResult => inputTypes.lower <: lowerResult?.lowerIfFlexible() + * inputType.lower <: lowerResult => inputType.lower <: lowerResult?.lowerIfFlexible() * i.e. this type is correct. We use this type, because this type more flexible. * * If U_1 <: U_2.lower .. U_2.upper, then we know only that U_1 <: U_2.upper. diff --git a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java index 23266871a5a..a5f414e7310 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/kotlin/builtins/KotlinBuiltIns.java @@ -277,8 +277,6 @@ public abstract class KotlinBuiltIns { public final FqNameUnsafe functionSupertype = fqNameUnsafe("Function"); - - public final FqName throwable = fqName("Throwable"); public final FqName comparable = fqName("Comparable");