Cleanup and reformart DelegatedPropertyResolver.kt

This commit is contained in:
Dmitriy Novozhilov
2019-12-26 10:52:40 +03:00
parent c8a1b876e8
commit 7728102a77
@@ -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
@@ -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,7 +296,7 @@ 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
@@ -340,7 +341,7 @@ class DelegatedPropertyResolver(
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)
} }
@@ -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 {
@@ -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())
@@ -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