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