minor: refactor cast into context operation

This commit is contained in:
Pavel Kirpichenkov
2020-03-24 17:53:28 +03:00
parent 5657afc35b
commit 568b21e31c
2 changed files with 4 additions and 8 deletions
@@ -33,8 +33,8 @@ class KotlinConstraintSystemCompleter(
} }
interface Context : VariableFixationFinder.Context, ResultTypeResolver.Context { interface Context : VariableFixationFinder.Context, ResultTypeResolver.Context {
val allTypeVariables: Map<TypeConstructorMarker, TypeVariableMarker>
override val notFixedTypeVariables: Map<TypeConstructorMarker, VariableWithConstraints> override val notFixedTypeVariables: Map<TypeConstructorMarker, VariableWithConstraints>
override val postponedTypeVariables: List<TypeVariableMarker> override val postponedTypeVariables: List<TypeVariableMarker>
// type can be proper if it not contains not fixed type variables // type can be proper if it not contains not fixed type variables
@@ -170,8 +170,6 @@ class KotlinConstraintSystemCompleter(
analyze: (PostponedResolvedAtom) -> Unit, analyze: (PostponedResolvedAtom) -> Unit,
fixationFinder: VariableFixationFinder fixationFinder: VariableFixationFinder
): Boolean { ): Boolean {
if (this !is NewConstraintSystem) return false
val isReturnArgumentOfAnotherLambda = postponedArguments.any { val isReturnArgumentOfAnotherLambda = postponedArguments.any {
it is LambdaWithTypeVariableAsExpectedTypeAtom && it.isReturnArgumentOfAnotherLambda it is LambdaWithTypeVariableAsExpectedTypeAtom && it.isReturnArgumentOfAnotherLambda
} }
@@ -186,7 +184,7 @@ class KotlinConstraintSystemCompleter(
return false return false
val expectedTypeVariable = val expectedTypeVariable =
atomExpectedType?.constructor?.takeIf { it in this.getBuilder().currentStorage().allTypeVariables } ?: return false atomExpectedType?.constructor?.takeIf { it in allTypeVariables } ?: return false
analyze(preparePostponedAtom(expectedTypeVariable, postponedAtom, expectedTypeVariable.builtIns, diagnosticsHolder) ?: return false) analyze(preparePostponedAtom(expectedTypeVariable, postponedAtom, expectedTypeVariable.builtIns, diagnosticsHolder) ?: return false)
@@ -202,8 +200,6 @@ class KotlinConstraintSystemCompleter(
diagnosticsHolder: KotlinDiagnosticsHolder, diagnosticsHolder: KotlinDiagnosticsHolder,
analyze: (PostponedResolvedAtom) -> Unit analyze: (PostponedResolvedAtom) -> Unit
): Boolean { ): Boolean {
if (this !is NewConstraintSystem) return false
val variable = variableForFixation.variable as? TypeConstructor ?: return false val variable = variableForFixation.variable as? TypeConstructor ?: return false
val hasProperAtom = postponedArguments.any { val hasProperAtom = postponedArguments.any {
when (it) { when (it) {
@@ -216,7 +212,7 @@ class KotlinConstraintSystemCompleter(
val postponedAtom = postponedArguments.firstOrNull() ?: return false val postponedAtom = postponedArguments.firstOrNull() ?: return false
val expectedTypeAtom = postponedAtom.expectedType val expectedTypeAtom = postponedAtom.expectedType
val expectedTypeVariable = val expectedTypeVariable =
expectedTypeAtom?.constructor?.takeIf { it in this.getBuilder().currentStorage().allTypeVariables } ?: variable expectedTypeAtom?.constructor?.takeIf { it in allTypeVariables } ?: variable
val shouldAnalyzeByEqualityExpectedTypeToVariable = val shouldAnalyzeByEqualityExpectedTypeToVariable =
hasProperAtom || !variableForFixation.hasProperConstraint || variableForFixation.hasOnlyTrivialProperConstraint hasProperAtom || !variableForFixation.hasProperConstraint || variableForFixation.hasOnlyTrivialProperConstraint
@@ -246,7 +246,7 @@ class NewConstraintSystemImpl(
return typeVariable in postponedTypeVariables return typeVariable in postponedTypeVariables
} }
// ConstraintInjector.Context // ConstraintInjector.Context, KotlinConstraintSystemCompleter.Context
override val allTypeVariables: Map<TypeConstructorMarker, TypeVariableMarker> override val allTypeVariables: Map<TypeConstructorMarker, TypeVariableMarker>
get() { get() {
checkState(State.BUILDING, State.COMPLETION, State.TRANSACTION) checkState(State.BUILDING, State.COMPLETION, State.TRANSACTION)