[FE 1.0] Cleanup PatternMatchingTypingVisitor.kt

This commit is contained in:
Dmitriy Novozhilov
2021-07-09 14:04:51 +03:00
committed by teamcityserver
parent 7b5a5f5682
commit f0c4d06fc9
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.diagnostics.Errors.* import org.jetbrains.kotlin.diagnostics.Errors.*
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.* import org.jetbrains.kotlin.resolve.*
@@ -149,7 +148,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
) )
} }
override fun getCalleeExpressionForSpecialCall(): KtExpression? = override fun getCalleeExpressionForSpecialCall(): KtExpression =
variable variable
override val valueExpression: KtExpression? override val valueExpression: KtExpression?
@@ -215,7 +214,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
val possibleTypesForSubject = val possibleTypesForSubject =
subject.typeInfo?.dataFlowInfo?.getStableTypes(subject.dataFlowValue, components.languageVersionSettings) subject.typeInfo?.dataFlowInfo?.getStableTypes(subject.dataFlowValue, components.languageVersionSettings)
?: emptySet() ?: emptySet()
checkSmartCastsInSubjectIfRequired(expression, contextBeforeSubject, subject.type, possibleTypesForSubject) checkSmartCastsInSubjectIfRequired(expression, contextBeforeSubject, subject.type, possibleTypesForSubject)
val dataFlowInfoForEntries = analyzeConditionsInWhenEntries(expression, contextAfterSubject, subject) val dataFlowInfoForEntries = analyzeConditionsInWhenEntries(expression, contextAfterSubject, subject)
@@ -274,7 +273,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
} }
if (illegalDeclarationString != null) { if (illegalDeclarationString != null) {
trace.report(Errors.ILLEGAL_DECLARATION_IN_WHEN_SUBJECT.on(subjectVariable, illegalDeclarationString)) trace.report(ILLEGAL_DECLARATION_IN_WHEN_SUBJECT.on(subjectVariable, illegalDeclarationString))
} }
} }
@@ -282,7 +281,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
ExpressionTypingUtils.newWritableScopeImpl(contextBeforeSubject, LexicalScopeKind.WHEN, components.overloadChecker) ExpressionTypingUtils.newWritableScopeImpl(contextBeforeSubject, LexicalScopeKind.WHEN, components.overloadChecker)
val (typeInfo, descriptor) = val (typeInfo, descriptor) =
components.localVariableResolver.process(subjectVariable, contextBeforeSubject, contextBeforeSubject.scope, facade) components.localVariableResolver.process(subjectVariable, contextBeforeSubject, contextBeforeSubject.scope, facade)
scopeWithSubjectVariable.addVariableDescriptor(descriptor) scopeWithSubjectVariable.addVariableDescriptor(descriptor)
@@ -389,12 +388,11 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
entryTypeInfo.dataFlowInfo entryTypeInfo.dataFlowInfo
} }
currentDataFlowInfo = currentDataFlowInfo = when {
when { entryType != null && KotlinBuiltIns.isNothing(entryType) -> currentDataFlowInfo
entryType != null && KotlinBuiltIns.isNothing(entryType) -> currentDataFlowInfo currentDataFlowInfo != null -> currentDataFlowInfo.or(entryDataFlowInfo)
currentDataFlowInfo != null -> currentDataFlowInfo.or(entryDataFlowInfo) else -> entryDataFlowInfo
else -> entryDataFlowInfo }
}
jumpOutPossible = jumpOutPossible or entryTypeInfo.jumpOutPossible jumpOutPossible = jumpOutPossible or entryTypeInfo.jumpOutPossible
} }
@@ -639,7 +637,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
if (!subjectType.containsError() && !TypeUtils.isNullableType(subjectType) && targetType.isMarkedNullable) { if (!subjectType.containsError() && !TypeUtils.isNullableType(subjectType) && targetType.isMarkedNullable) {
val element = typeReferenceAfterIs.typeElement val element = typeReferenceAfterIs.typeElement
assert(element is KtNullableType) { "element must be instance of " + KtNullableType::class.java.name } assert(element is KtNullableType) { "element must be instance of " + KtNullableType::class.java.name }
context.trace.report(Errors.USELESS_NULLABLE_CHECK.on(element as KtNullableType)) context.trace.report(USELESS_NULLABLE_CHECK.on(element as KtNullableType))
} }
val typesAreCompatible = checkTypeCompatibility(context, targetType, subjectType, typeReferenceAfterIs) val typesAreCompatible = checkTypeCompatibility(context, targetType, subjectType, typeReferenceAfterIs)
@@ -650,7 +648,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
} }
if (CastDiagnosticsUtil.isCastErased(subjectType, targetType, KotlinTypeChecker.DEFAULT)) { if (CastDiagnosticsUtil.isCastErased(subjectType, targetType, KotlinTypeChecker.DEFAULT)) {
context.trace.report(Errors.CANNOT_CHECK_FOR_ERASED.on(typeReferenceAfterIs, targetType)) context.trace.report(CANNOT_CHECK_FOR_ERASED.on(typeReferenceAfterIs, targetType))
} }
return context.dataFlowInfo.let { return context.dataFlowInfo.let {
ConditionalDataFlowInfo(it.establishSubtyping(subjectDataFlowValue, targetType, components.languageVersionSettings), it) ConditionalDataFlowInfo(it.establishSubtyping(subjectDataFlowValue, targetType, components.languageVersionSettings), it)
@@ -682,7 +680,7 @@ class PatternMatchingTypingVisitor internal constructor(facade: ExpressionTyping
} }
if (CastDiagnosticsUtil.isRefinementUseless(possibleTypes, targetType, false)) { if (CastDiagnosticsUtil.isRefinementUseless(possibleTypes, targetType, false)) {
context.trace.report(Errors.USELESS_IS_CHECK.on(isCheck, !negated)) context.trace.report(USELESS_IS_CHECK.on(isCheck, !negated))
} }
} }