Cleanup and reformart DelegatedPropertyResolver.kt
This commit is contained in:
@@ -108,7 +108,7 @@ class DelegatedPropertyResolver(
|
||||
val provideDelegateResolvedCall = trace.bindingContext.get(PROVIDE_DELEGATE_RESOLVED_CALL, variableDescriptor)
|
||||
if (provideDelegateResolvedCall != null) {
|
||||
return provideDelegateResolvedCall.resultingDescriptor.returnType
|
||||
?: throw AssertionError("No return type fore 'provideDelegate' of ${delegateExpression.text}")
|
||||
?: throw AssertionError("No return type fore 'provideDelegate' of ${delegateExpression.text}")
|
||||
}
|
||||
return byExpressionType
|
||||
}
|
||||
@@ -126,7 +126,7 @@ class DelegatedPropertyResolver(
|
||||
resolveGetSetValueMethod(variableDescriptor, delegateExpression, delegateType, trace, initializerScope, dataFlowInfo, true)
|
||||
|
||||
val resolvedCall = trace.bindingContext.get(DELEGATED_PROPERTY_RESOLVED_CALL, variableDescriptor.getter)
|
||||
return if (resolvedCall != null) resolvedCall.resultingDescriptor.returnType else null
|
||||
return resolvedCall?.resultingDescriptor?.returnType
|
||||
}
|
||||
|
||||
private val isOperatorProvideDelegateSupported: Boolean
|
||||
@@ -147,7 +147,7 @@ class DelegatedPropertyResolver(
|
||||
/* Do not check return type of get() method of delegate for properties with DeferredType because property type is taken from it */
|
||||
if (propertyType !is DeferredType && returnType != null && !KotlinTypeChecker.DEFAULT.isSubtypeOf(returnType, propertyType)) {
|
||||
val call = trace.bindingContext.get(DELEGATED_PROPERTY_CALL, variableDescriptor.getter)
|
||||
?: throw AssertionError("Call should exists for ${variableDescriptor.getter}")
|
||||
?: throw AssertionError("Call should exists for ${variableDescriptor.getter}")
|
||||
trace.report(
|
||||
DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH.on(
|
||||
delegateExpression, renderCall(call, trace.bindingContext), variableDescriptor.type, returnType
|
||||
@@ -185,7 +185,7 @@ class DelegatedPropertyResolver(
|
||||
isGet: Boolean
|
||||
) {
|
||||
val accessor = (if (isGet) propertyDescriptor.getter else propertyDescriptor.setter)
|
||||
?: throw AssertionError("Delegated property should have getter/setter $propertyDescriptor ${delegateExpression.text}")
|
||||
?: throw AssertionError("Delegated property should have getter/setter $propertyDescriptor ${delegateExpression.text}")
|
||||
|
||||
if (trace.bindingContext.get(DELEGATED_PROPERTY_CALL, accessor) != null) return
|
||||
|
||||
@@ -262,7 +262,8 @@ class DelegatedPropertyResolver(
|
||||
val resolutionErrorFactory = when {
|
||||
delegateOperatorResults.isSingleResult ||
|
||||
delegateOperatorResults.isIncomplete ||
|
||||
delegateOperatorResults.resultCode == OverloadResolutionResults.Code.MANY_FAILED_CANDIDATES -> DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE
|
||||
delegateOperatorResults.resultCode == OverloadResolutionResults.Code.MANY_FAILED_CANDIDATES ->
|
||||
DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE
|
||||
|
||||
delegateOperatorResults.isAmbiguity -> DELEGATE_SPECIAL_FUNCTION_AMBIGUITY
|
||||
|
||||
@@ -286,7 +287,7 @@ class DelegatedPropertyResolver(
|
||||
dataFlowInfo: DataFlowInfo
|
||||
) {
|
||||
if (!isOperatorProvideDelegateSupported) return
|
||||
if (trace.bindingContext.get(BindingContext.PROVIDE_DELEGATE_CALL, propertyDescriptor) != null) return
|
||||
if (trace.bindingContext.get(PROVIDE_DELEGATE_CALL, propertyDescriptor) != null) return
|
||||
|
||||
val traceForProvideDelegate = TemporaryBindingTrace.create(trace, "trace to resolve provideDelegate method")
|
||||
|
||||
@@ -295,8 +296,8 @@ class DelegatedPropertyResolver(
|
||||
traceForProvideDelegate, initializerScope, dataFlowInfo
|
||||
)
|
||||
if (!provideDelegateResults.isSuccess) {
|
||||
val call = traceForProvideDelegate.bindingContext.get(BindingContext.PROVIDE_DELEGATE_CALL, propertyDescriptor)
|
||||
?: throw AssertionError("'getDelegatedPropertyConventionMethod' didn't record a call")
|
||||
val call = traceForProvideDelegate.bindingContext.get(PROVIDE_DELEGATE_CALL, propertyDescriptor)
|
||||
?: throw AssertionError("'getDelegatedPropertyConventionMethod' didn't record a call")
|
||||
val shouldCommitTrace = reportDelegateErrorIfCandidateExists(
|
||||
traceForProvideDelegate, call, provideDelegateResults, byExpression
|
||||
)
|
||||
@@ -335,12 +336,12 @@ class DelegatedPropertyResolver(
|
||||
val delegateFunctionsScope = ScopeUtils.makeScopeForDelegateConventionFunctions(scopeForDelegate, propertyDescriptor)
|
||||
|
||||
val accessor = (if (isGet) propertyDescriptor.getter else propertyDescriptor.setter)
|
||||
?: throw AssertionError("Delegated property should have getter/setter $propertyDescriptor ${delegateExpression.text}")
|
||||
?: throw AssertionError("Delegated property should have getter/setter $propertyDescriptor ${delegateExpression.text}")
|
||||
|
||||
val expectedType = if (isComplete && isGet && propertyDescriptor.type !is DeferredType)
|
||||
propertyDescriptor.type
|
||||
else
|
||||
TypeUtils.NO_EXPECTED_TYPE
|
||||
NO_EXPECTED_TYPE
|
||||
|
||||
val context =
|
||||
knownContext ?: ExpressionTypingContext.newContext(
|
||||
@@ -392,7 +393,7 @@ class DelegatedPropertyResolver(
|
||||
): ExpressionTypingContext {
|
||||
val delegateFunctionsScope = ScopeUtils.makeScopeForDelegateConventionFunctions(scopeForDelegate, propertyDescriptor)
|
||||
return ExpressionTypingContext.newContext(
|
||||
trace, delegateFunctionsScope, dataFlowInfo, TypeUtils.NO_EXPECTED_TYPE,
|
||||
trace, delegateFunctionsScope, dataFlowInfo, NO_EXPECTED_TYPE,
|
||||
languageVersionSettings, dataFlowValueFactory, inferenceExtension
|
||||
)
|
||||
}
|
||||
@@ -418,7 +419,14 @@ class DelegatedPropertyResolver(
|
||||
initializerScope: LexicalScope,
|
||||
dataFlowInfo: DataFlowInfo
|
||||
): OverloadResolutionResults<FunctionDescriptor> {
|
||||
val context = ExpressionTypingContext.newContext(trace, initializerScope, dataFlowInfo, NO_EXPECTED_TYPE, languageVersionSettings, dataFlowValueFactory)
|
||||
val context = ExpressionTypingContext.newContext(
|
||||
trace,
|
||||
initializerScope,
|
||||
dataFlowInfo,
|
||||
NO_EXPECTED_TYPE,
|
||||
languageVersionSettings,
|
||||
dataFlowValueFactory
|
||||
)
|
||||
return getProvideDelegateMethod(propertyDescriptor, delegateExpression, delegateExpressionType, context)
|
||||
}
|
||||
|
||||
@@ -439,7 +447,7 @@ class DelegatedPropertyResolver(
|
||||
val receiver = ExpressionReceiver.create(delegateExpression, delegateExpressionType, context.trace.bindingContext)
|
||||
|
||||
val (provideDelegateCall, provideDelegateResults) =
|
||||
fakeCallResolver.makeAndResolveFakeCallInContext(receiver, context, arguments, functionName, delegateExpression)
|
||||
fakeCallResolver.makeAndResolveFakeCallInContext(receiver, context, arguments, functionName, delegateExpression)
|
||||
|
||||
if (provideDelegateResults.isSingleResult) {
|
||||
context.trace.record(DELEGATE_EXPRESSION_TO_PROVIDE_DELEGATE_CALL, delegateExpression, provideDelegateCall)
|
||||
@@ -452,7 +460,7 @@ class DelegatedPropertyResolver(
|
||||
//TODO: diagnostics rendering does not belong here
|
||||
private fun renderCall(call: Call, context: BindingContext): String {
|
||||
val calleeExpression = call.calleeExpression
|
||||
?: throw AssertionError("CalleeExpression should exists for fake call of convention method")
|
||||
?: throw AssertionError("CalleeExpression should exists for fake call of convention method")
|
||||
|
||||
return call.valueArguments.joinToString(
|
||||
prefix = "${calleeExpression.text}(",
|
||||
@@ -649,7 +657,7 @@ class DelegatedPropertyResolver(
|
||||
val expectedType: KotlinType,
|
||||
val variableDescriptor: VariableDescriptorWithAccessors,
|
||||
val delegateExpression: KtExpression,
|
||||
val scopeForDelegate: LexicalScope,
|
||||
private val scopeForDelegate: LexicalScope,
|
||||
val trace: BindingTrace,
|
||||
val dataFlowInfo: DataFlowInfo
|
||||
) : ConstraintSystemCompleter {
|
||||
@@ -657,7 +665,7 @@ class DelegatedPropertyResolver(
|
||||
val returnType = resolvedCall.candidateDescriptor.returnType ?: return
|
||||
|
||||
val typeVariableSubstitutor = constraintSystem.typeVariableSubstitutors[resolvedCall.call.toHandle()]
|
||||
?: throw AssertionError("No substitutor in the system for call: " + resolvedCall.call)
|
||||
?: throw AssertionError("No substitutor in the system for call: " + resolvedCall.call)
|
||||
|
||||
val traceToResolveConventionMethods =
|
||||
TemporaryBindingTrace.create(trace, "Trace to resolve delegated property convention methods")
|
||||
@@ -671,7 +679,7 @@ class DelegatedPropertyResolver(
|
||||
if (conventionMethodFound(getValueResults)) {
|
||||
val getValueDescriptor = getValueResults.resultingDescriptor
|
||||
val getValueReturnType = getValueDescriptor.returnType
|
||||
if (getValueReturnType != null && !TypeUtils.noExpectedType(expectedType)) {
|
||||
if (getValueReturnType != null && !noExpectedType(expectedType)) {
|
||||
val returnTypeInSystem = typeVariableSubstitutor.substitute(getValueReturnType, Variance.INVARIANT)
|
||||
if (returnTypeInSystem != null) {
|
||||
constraintSystem.addSubtypeConstraint(returnTypeInSystem, expectedType, FROM_COMPLETER.position())
|
||||
@@ -724,7 +732,7 @@ class DelegatedPropertyResolver(
|
||||
dispatchReceiverOnly = true
|
||||
)
|
||||
return provideDelegateReturnType
|
||||
?: throw AssertionError("No return type fore 'provideDelegate' of ${delegateExpression.text}")
|
||||
?: throw AssertionError("No return type fore 'provideDelegate' of ${delegateExpression.text}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -740,8 +748,11 @@ class DelegatedPropertyResolver(
|
||||
) {
|
||||
val extensionReceiver = variableDescriptor.extensionReceiverParameter
|
||||
val dispatchReceiver = variableDescriptor.dispatchReceiverParameter
|
||||
val typeOfThis = (if (dispatchReceiverOnly) dispatchReceiver?.type else (extensionReceiver?.type ?: dispatchReceiver?.type))
|
||||
?: builtIns.nullableNothingType
|
||||
val typeOfThis = if (dispatchReceiverOnly) {
|
||||
dispatchReceiver?.type
|
||||
} else {
|
||||
extensionReceiver?.type ?: dispatchReceiver?.type
|
||||
} ?: builtIns.nullableNothingType
|
||||
|
||||
val valueParameters = resultingDescriptor.valueParameters
|
||||
if (valueParameters.isEmpty()) return
|
||||
|
||||
Reference in New Issue
Block a user