Fix delegated property resolve with intermediate ID provideDelegate

#KT-37406 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-04-09 03:33:35 +03:00
parent 0262e9de2f
commit a7b959b88b
14 changed files with 100 additions and 11 deletions
@@ -92,7 +92,15 @@ class DelegatedPropertyInferenceSession(
object InferenceSessionForExistingCandidates : InferenceSession {
override fun shouldRunCompletion(candidate: KotlinResolutionCandidate): Boolean {
return !ErrorUtils.isError(candidate.resolvedCall.candidateDescriptor)
if (ErrorUtils.isError(candidate.resolvedCall.candidateDescriptor)) return false
val builder = candidate.getSystem().getBuilder()
for ((_, variable) in builder.currentStorage().notFixedTypeVariables) {
val hasProperConstraint = variable.constraints.any { candidate.getSystem().getBuilder().isProperType(it.type) }
if (hasProperConstraint) return true
}
return false
}
override fun addPartialCallInfo(callInfo: PartialCallInfo) {}
@@ -111,4 +119,21 @@ object InferenceSessionForExistingCandidates : InferenceSession {
override fun shouldCompleteResolvedSubAtomsOf(resolvedCallAtom: ResolvedCallAtom): Boolean {
return !ErrorUtils.isError(resolvedCallAtom.candidateDescriptor)
}
override fun computeCompletionMode(
candidate: KotlinResolutionCandidate
): KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode? {
// this is a hack to mitigate questionable behavior in delegated properties design, namely:
// see test DelegatedProperty.ProvideDelegate#testHostAndReceiver2
// Normally, provideDelegate should be analyzed in INDEPENDENT mode, but now in OI there is one corner case, which
// doesn't fit into this design
val builder = candidate.getSystem().getBuilder()
for ((_, variable) in builder.currentStorage().notFixedTypeVariables) {
val hasProperConstraint = variable.constraints.any { candidate.getSystem().getBuilder().isProperType(it.type) }
if (hasProperConstraint) return null
}
return KotlinConstraintSystemCompleter.ConstraintSystemCompletionMode.PARTIAL
}
}
@@ -406,7 +406,7 @@ class DelegatedPropertyResolver(
): ExpressionTypingContext {
return ExpressionTypingContext.newContext(
trace, scopeForDelegate, dataFlowInfo,
NO_EXPECTED_TYPE, ContextDependency.DEPENDENT, StatementFilter.NONE,
NO_EXPECTED_TYPE, ContextDependency.INDEPENDENT, StatementFilter.NONE,
languageVersionSettings, dataFlowValueFactory, inferenceExtension
)
}
@@ -157,6 +157,8 @@ abstract class ManyCandidatesResolver<D : CallableDescriptor>(
return allCandidates
}
override fun computeCompletionMode(candidate: KotlinResolutionCandidate) = null
private fun PartialCallInfo.asCallResolutionResult(
diagnosticsHolder: KotlinDiagnosticsHolder.SimpleHolder,
commonSystem: NewConstraintSystem