[NI] Extract FE 1.0 specific part from NewCommonSuperTypeCalculator

This commit is contained in:
Dmitriy Novozhilov
2020-08-26 10:51:54 +03:00
parent b21a0213df
commit 12fbb93871
12 changed files with 36 additions and 34 deletions
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.resolve.calls
import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext
fun NewCommonSuperTypeCalculator.commonSuperType(types: List<UnwrappedType>): UnwrappedType {
return SimpleClassicTypeSystemContext.commonSuperType(types) as UnwrappedType
}
@@ -16,18 +16,14 @@
package org.jetbrains.kotlin.resolve.calls
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.AbstractFlexibilityChecker.hasDifferentFlexibilityAtDepth
import org.jetbrains.kotlin.types.AbstractNullabilityChecker
import org.jetbrains.kotlin.types.AbstractNullabilityChecker.hasPathByNotMarkedNullableNodes
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext
import org.jetbrains.kotlin.types.AbstractTypeChecker
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
import org.jetbrains.kotlin.types.model.*
object NewCommonSuperTypeCalculator {
// TODO: Bridge for old calls
fun commonSuperType(types: List<UnwrappedType>): UnwrappedType {
return SimpleClassicTypeSystemContext.commonSuperType(types) as UnwrappedType
}
fun TypeSystemCommonSuperTypesContext.commonSuperType(types: List<KotlinTypeMarker>): KotlinTypeMarker {
val maxDepth = types.maxOfOrNull { it.typeDepth() } ?: 0
return commonSuperType(types, -maxDepth, true)
@@ -96,8 +92,8 @@ object NewCommonSuperTypeCalculator {
contextStubTypesEqualToAnything: AbstractTypeCheckerContext,
contextStubTypesNotEqual: AbstractTypeCheckerContext
): SimpleTypeMarker {
if (types.any { it is ErrorType }) {
return ErrorUtils.createErrorType("CST(${types.joinToString()}")
if (types.any { it.isError() }) {
return createErrorType("CST(${types.joinToString()}")
}
// i.e. result type also should be marked nullable
@@ -25,8 +25,6 @@ abstract class AbstractTypeApproximator(val ctx: TypeSystemInferenceExtensionCon
const val CACHE_FOR_INCORPORATION_MAX_SIZE = 500
}
abstract fun createErrorType(message: String): SimpleTypeMarker
// null means that this input type is the result, i.e. input type not contains not-allowed kind of types
// type <: resultType
fun approximateToSuperType(type: KotlinTypeMarker, conf: TypeApproximatorConfiguration): KotlinTypeMarker? =
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.resolve.calls.components.ClassicTypeSystemContextForCS
import org.jetbrains.kotlin.types.model.SimpleTypeMarker
class TypeApproximator(builtIns: KotlinBuiltIns) : AbstractTypeApproximator(ClassicTypeSystemContextForCS(builtIns)) {
fun approximateDeclarationType(baseType: KotlinType, local: Boolean, languageVersionSettings: LanguageVersionSettings): UnwrappedType {
@@ -39,9 +38,5 @@ class TypeApproximator(builtIns: KotlinBuiltIns) : AbstractTypeApproximator(Clas
// resultType <: type
fun approximateToSubType(type: UnwrappedType, conf: TypeApproximatorConfiguration): UnwrappedType? =
super.approximateToSubType(type, conf) as UnwrappedType?
override fun createErrorType(message: String): SimpleTypeMarker {
return ErrorUtils.createErrorType(message)
}
}