Check postponed type variables to determine suitability for builder inference (during shouldRunCompletion check) more careful

^KT-42139 Fixed
This commit is contained in:
Victor Petukhov
2021-08-03 13:00:46 +03:00
committed by teamcityserver
parent cf3bd016be
commit b6cb393796
2 changed files with 13 additions and 8 deletions
@@ -94,7 +94,7 @@ class BuilderInferenceSession(
return subResolvedAtoms?.any { it.hasPostponed() } == true
}
if (!candidate.isSuitableForBuilderInference()) {
if (!candidate.resolvedCall.isSuitableForBuilderInference()) {
return true
}
@@ -108,13 +108,18 @@ class BuilderInferenceSession(
} || candidate.getSubResolvedAtoms().any { it.hasPostponed() }
}
private fun KotlinResolutionCandidate.isSuitableForBuilderInference(): Boolean {
val extensionReceiver = resolvedCall.extensionReceiverArgument
val dispatchReceiver = resolvedCall.dispatchReceiverArgument
private fun ResolvedCallAtom.isSuitableForBuilderInference(): Boolean {
val extensionReceiver = extensionReceiverArgument
val dispatchReceiver = dispatchReceiverArgument
val resolvedAtoms = subResolvedAtoms
return when {
resolvedAtoms != null && resolvedAtoms.map { it.atom }.filterIsInstance<SubKotlinCallArgument>().any {
it.callResult.resultCallAtom.isSuitableForBuilderInference()
} -> true
extensionReceiver == null && dispatchReceiver == null -> false
dispatchReceiver?.receiver?.stableType?.containsStubType() == true -> true
extensionReceiver?.receiver?.stableType?.containsStubType() == true -> resolvedCall.candidateDescriptor.hasBuilderInferenceAnnotation()
extensionReceiver?.receiver?.stableType?.containsStubType() == true -> candidateDescriptor.hasBuilderInferenceAnnotation()
else -> false
}
}
@@ -11,12 +11,12 @@ fun f1(): Sequence<List<Int>> = sequence {
}
fun f2(): Sequence<List<Int>> = sequence {
select(<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>yield<!>(<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>myEmptyList<!>()), yield(<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>myEmptyList<!>()))
select(yield(myEmptyList()), yield(myEmptyList()))
}
fun f3(): Sequence<List<Int>> = sequence {
if (true) <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>yield<!>(<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>myEmptyList<!>()) // [NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER] Not enough information to infer type variable T
else yield(<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>myEmptyList<!>()) // [NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER] Not enough information to infer type variable T
if (true) yield(myEmptyList()) // [NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER] Not enough information to infer type variable T
else yield(myEmptyList()) // [NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER] Not enough information to infer type variable T
}
fun box(): String {