[Core API] Introduce TypeConstructor.refine
This commit introduces TypeConstructor.refine method. It's implementation can be roughly split in three parts: - trivial implementations which just return 'this': mostly, it used for typeConstructors which can not be refined at all (e.g. IntegerValueTypeConstructor and other special cases of constructors) - delegating implementations which call 'refine' recursively for component typeConstructors -- obviously, they are used in composite typeConstructors (like IntersectionTypeConstructor) - finally, the most interesting one is in 'AbstractTypeConstructor' which returns lightweight wrapper called 'ModuleViewTypeConstructor'. The idea here is to propagate refinement to supertypes without eagerly computing them all. VERY IMPORTANT CAVEAT of TypeConstructor.refine is that call to this method CAN NOT add new supertypes, so returned supertypes are not entirely "valid". See the KDoc for TypeConstructor.refine for details
This commit is contained in:
+5
@@ -27,8 +27,10 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
import org.jetbrains.kotlin.types.TypeConstructor
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
|
||||
import org.jetbrains.kotlin.types.checker.NewTypeVariableConstructor
|
||||
import org.jetbrains.kotlin.types.model.TypeVariableMarker
|
||||
import org.jetbrains.kotlin.types.refinement.TypeRefinement
|
||||
|
||||
|
||||
class TypeVariableTypeConstructor(private val builtIns: KotlinBuiltIns, val debugName: String) : TypeConstructor,
|
||||
@@ -41,6 +43,9 @@ class TypeVariableTypeConstructor(private val builtIns: KotlinBuiltIns, val debu
|
||||
|
||||
override fun getBuiltIns() = builtIns
|
||||
|
||||
@TypeRefinement
|
||||
override fun refine(kotlinTypeRefiner: KotlinTypeRefiner): TypeConstructor = this
|
||||
|
||||
override fun toString() = "TypeVariable($debugName)"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user