[FE 1.0] Check for readiness to fix for all type variables after try analysing a lambda with the builder inference

^KT-50498 Fixed
This commit is contained in:
Victor Petukhov
2021-12-23 18:50:57 +03:00
committed by teamcity
parent bb34a74abb
commit d3ee284461
@@ -143,8 +143,9 @@ class KotlinConstraintSystemCompleter(
continue continue
// Stage 7: try to complete call with the builder inference if there are uninferred type variables // Stage 7: try to complete call with the builder inference if there are uninferred type variables
val areThereAppearedProperConstraintsForSomeVariable = val areThereAppearedProperConstraintsForSomeVariable = tryToCompleteWithBuilderInference(
tryToCompleteWithBuilderInference(completionMode, topLevelType, postponedArguments, analyze) completionMode, topLevelAtoms, topLevelType, postponedArguments, collectVariablesFromContext, analyze
)
if (areThereAppearedProperConstraintsForSomeVariable) if (areThereAppearedProperConstraintsForSomeVariable)
continue continue
@@ -166,8 +167,10 @@ class KotlinConstraintSystemCompleter(
private fun ConstraintSystemCompletionContext.tryToCompleteWithBuilderInference( private fun ConstraintSystemCompletionContext.tryToCompleteWithBuilderInference(
completionMode: ConstraintSystemCompletionMode, completionMode: ConstraintSystemCompletionMode,
topLevelAtoms: List<ResolvedAtom>,
topLevelType: UnwrappedType, topLevelType: UnwrappedType,
postponedArguments: List<PostponedResolvedAtom>, postponedArguments: List<PostponedResolvedAtom>,
collectVariablesFromContext: Boolean,
analyze: (PostponedResolvedAtom) -> Unit analyze: (PostponedResolvedAtom) -> Unit
): Boolean { ): Boolean {
if (completionMode == ConstraintSystemCompletionMode.PARTIAL) return false if (completionMode == ConstraintSystemCompletionMode.PARTIAL) return false
@@ -180,7 +183,6 @@ class KotlinConstraintSystemCompleter(
val lambdaArguments = postponedArguments.filterIsInstance<ResolvedLambdaAtom>().takeIf { it.isNotEmpty() } ?: return false val lambdaArguments = postponedArguments.filterIsInstance<ResolvedLambdaAtom>().takeIf { it.isNotEmpty() } ?: return false
val useBuilderInferenceWithoutAnnotation = val useBuilderInferenceWithoutAnnotation =
languageVersionSettings.supportsFeature(LanguageFeature.UseBuilderInferenceWithoutAnnotation) languageVersionSettings.supportsFeature(LanguageFeature.UseBuilderInferenceWithoutAnnotation)
val allNotFixedInputTypeVariables = mutableSetOf<TypeVariableTypeConstructorMarker>()
for (argument in lambdaArguments) { for (argument in lambdaArguments) {
if (!argument.atom.hasBuilderInferenceAnnotation && !useBuilderInferenceWithoutAnnotation) if (!argument.atom.hasBuilderInferenceAnnotation && !useBuilderInferenceWithoutAnnotation)
@@ -191,8 +193,6 @@ class KotlinConstraintSystemCompleter(
if (notFixedInputTypeVariables.isEmpty()) continue if (notFixedInputTypeVariables.isEmpty()) continue
allNotFixedInputTypeVariables.addAll(notFixedInputTypeVariables)
for (variable in notFixedInputTypeVariables) { for (variable in notFixedInputTypeVariables) {
getBuilder().markPostponedVariable(notFixedTypeVariables.getValue(variable).typeVariable) getBuilder().markPostponedVariable(notFixedTypeVariables.getValue(variable).typeVariable)
} }
@@ -201,7 +201,7 @@ class KotlinConstraintSystemCompleter(
} }
val variableForFixation = variableFixationFinder.findFirstVariableForFixation( val variableForFixation = variableFixationFinder.findFirstVariableForFixation(
this, allNotFixedInputTypeVariables.toList(), postponedArguments, completionMode, topLevelType this, getOrderedAllTypeVariables(collectVariablesFromContext, topLevelAtoms), postponedArguments, completionMode, topLevelType
) )
// continue completion (rerun stages) only if ready for fixation variables with proper constraints have appeared // continue completion (rerun stages) only if ready for fixation variables with proper constraints have appeared