Move util functions from KotlinToResolvedCallTransformer to resolvedCallUtil.kt
This commit is contained in:
+1
-1
@@ -66,7 +66,7 @@ public class OverloadResolutionResultsUtil {
|
||||
newResolvedCall = null;
|
||||
}
|
||||
if (newResolvedCall != null) {
|
||||
if (!KotlinToResolvedCallTransformerKt.hasInferredReturnType(newResolvedCall)) {
|
||||
if (!ResolvedCallUtilKt.hasInferredReturnType(newResolvedCall)) {
|
||||
return null;
|
||||
}
|
||||
} else if (!((MutableResolvedCall<D>) resultingCall).hasInferredReturnType()) {
|
||||
|
||||
+1
-63
@@ -6,12 +6,8 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.tower
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
@@ -25,45 +21,26 @@ import org.jetbrains.kotlin.resolve.calls.checkers.AdditionalTypeChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
||||
import org.jetbrains.kotlin.resolve.calls.components.AdditionalDiagnosticReporter
|
||||
import org.jetbrains.kotlin.resolve.calls.components.isVararg
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.context.CallPosition
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.buildResultingSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.FreshVariableNewTypeSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutorByConstructorMap
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.substitute
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.substituteAndApproximateTypes
|
||||
import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.resolvedCallUtil.makeNullableTypeIfSafeReceiver
|
||||
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.SmartCastManager
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy
|
||||
import org.jetbrains.kotlin.resolve.calls.util.makeNullableTypeIfSafeReceiver
|
||||
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant
|
||||
import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor
|
||||
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstant
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.CastImplicitClassReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitClassReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.NewCapturedType
|
||||
import org.jetbrains.kotlin.types.expressions.DataFlowAnalyzer
|
||||
import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
|
||||
import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContextDelegate
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||
import org.jetbrains.kotlin.types.typeUtil.makeNullable
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.compactIfPossible
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
class KotlinToResolvedCallTransformer(
|
||||
@@ -559,42 +536,3 @@ class KotlinToResolvedCallTransformer(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun CandidateApplicability.toResolutionStatus(): ResolutionStatus = when (this) {
|
||||
CandidateApplicability.RESOLVED,
|
||||
CandidateApplicability.RESOLVED_LOW_PRIORITY,
|
||||
CandidateApplicability.RESOLVED_WITH_ERROR,
|
||||
CandidateApplicability.RESOLVED_NEED_PRESERVE_COMPATIBILITY -> ResolutionStatus.SUCCESS
|
||||
CandidateApplicability.INAPPLICABLE_WRONG_RECEIVER -> ResolutionStatus.RECEIVER_TYPE_ERROR
|
||||
CandidateApplicability.UNSAFE_CALL -> ResolutionStatus.UNSAFE_CALL_ERROR
|
||||
else -> ResolutionStatus.OTHER_ERROR
|
||||
}
|
||||
|
||||
fun ResolvedCall<*>.isNewNotCompleted(): Boolean {
|
||||
if (this is NewVariableAsFunctionResolvedCallImpl) {
|
||||
return !functionCall.isCompleted
|
||||
}
|
||||
if (this is NewResolvedCallImpl<*>) {
|
||||
return !isCompleted
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
fun NewResolvedCallImpl<*>.hasInferredReturnType(): Boolean {
|
||||
if (isNewNotCompleted()) return false
|
||||
|
||||
val returnType = this.resultingDescriptor.returnType ?: return false
|
||||
return !returnType.contains { ErrorUtils.isUninferredParameter(it) }
|
||||
}
|
||||
|
||||
private fun CallableMemberDescriptor.isNotSimpleCall(): Boolean =
|
||||
typeParameters.isNotEmpty() ||
|
||||
(returnType?.let { type ->
|
||||
type.contains {
|
||||
it is NewCapturedType ||
|
||||
it.constructor is IntegerLiteralTypeConstructor ||
|
||||
it is DefinitelyNotNullType ||
|
||||
it is StubTypeForBuilderInference
|
||||
}
|
||||
} ?: false)
|
||||
|
||||
|
||||
@@ -5,26 +5,28 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.calls.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
import org.jetbrains.kotlin.psi.KtPsiUtil
|
||||
import org.jetbrains.kotlin.psi.KtThisExpression
|
||||
import org.jetbrains.kotlin.psi.ValueArgument
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isSafeCall
|
||||
import org.jetbrains.kotlin.resolve.calls.context.CallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory
|
||||
import org.jetbrains.kotlin.resolve.calls.results.ResolutionStatus
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.getReceiverValueWithSmartCast
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.*
|
||||
import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getOwnerForEffectiveDispatchReceiverParameter
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ClassValueReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.NewCapturedType
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
|
||||
// it returns true if call has no dispatch receiver (e.g. resulting descriptor is top-level function or local variable)
|
||||
// or call receiver is effectively `this` instance (explicitly or implicitly) of resulting descriptor
|
||||
@@ -95,4 +97,33 @@ fun KtCallElement.getArgumentByParameterIndex(index: Int, context: BindingContex
|
||||
val resolvedCall = getResolvedCall(context) ?: return emptyList()
|
||||
val parameterToProcess = resolvedCall.resultingDescriptor.valueParameters.getOrNull(index) ?: return emptyList()
|
||||
return resolvedCall.valueArguments[parameterToProcess]?.arguments ?: emptyList()
|
||||
}
|
||||
fun CallableMemberDescriptor.isNotSimpleCall(): Boolean =
|
||||
typeParameters.isNotEmpty() ||
|
||||
(returnType?.let { type ->
|
||||
type.contains {
|
||||
it is NewCapturedType ||
|
||||
it.constructor is IntegerLiteralTypeConstructor ||
|
||||
it is DefinitelyNotNullType ||
|
||||
it is StubTypeForBuilderInference
|
||||
}
|
||||
} ?: false)
|
||||
|
||||
fun ResolvedCall<*>.isNewNotCompleted(): Boolean = if (this is NewAbstractResolvedCall) !isCompleted else false
|
||||
|
||||
fun ResolvedCall<*>.hasInferredReturnType(): Boolean {
|
||||
if (isNewNotCompleted()) return false
|
||||
|
||||
val returnType = this.resultingDescriptor.returnType ?: return false
|
||||
return !returnType.contains { ErrorUtils.isUninferredParameter(it) }
|
||||
}
|
||||
|
||||
fun CandidateApplicability.toResolutionStatus(): ResolutionStatus = when (this) {
|
||||
CandidateApplicability.RESOLVED,
|
||||
CandidateApplicability.RESOLVED_LOW_PRIORITY,
|
||||
CandidateApplicability.RESOLVED_WITH_ERROR,
|
||||
CandidateApplicability.RESOLVED_NEED_PRESERVE_COMPATIBILITY -> ResolutionStatus.SUCCESS
|
||||
CandidateApplicability.INAPPLICABLE_WRONG_RECEIVER -> ResolutionStatus.RECEIVER_TYPE_ERROR
|
||||
CandidateApplicability.UNSAFE_CALL -> ResolutionStatus.UNSAFE_CALL_ERROR
|
||||
else -> ResolutionStatus.OTHER_ERROR
|
||||
}
|
||||
Reference in New Issue
Block a user