Implement makeNullableAsSpecified for TypeTemplate properly

This change fixes an SOE in isCastErased:
    @JvmStatic
    fun isCastErased(supertype: KotlinType, subtype: KotlinType, typeChecker: KotlinTypeChecker): Boolean {
        if (supertype.isMarkedNullable || subtype.isMarkedNullable) {
            return isCastErased(TypeUtils.makeNotNullable(supertype), TypeUtils.makeNotNullable(subtype), typeChecker)
        }

TypeUtils.makeNotNullable(TypeTemplate) should not return the same object
if isMarkedNullable returned true on the instance


 #KT-15516 Fixed
This commit is contained in:
Denis Zharkov
2017-01-31 16:18:31 +03:00
parent dc57f97196
commit e9262b875b
3 changed files with 31 additions and 3 deletions
@@ -56,11 +56,15 @@ import javax.inject.Inject
class TypeTemplate(
val typeVariable: TypeVariable,
val coroutineInferenceData: CoroutineInferenceData
) : FlexibleType(typeVariable.originalTypeParameter.builtIns.nothingType, typeVariable.originalTypeParameter.builtIns.nullableAnyType) {
val coroutineInferenceData: CoroutineInferenceData,
nullable: Boolean = true
) : FlexibleType(
typeVariable.originalTypeParameter.builtIns.nothingType,
typeVariable.originalTypeParameter.builtIns.anyType.makeNullableAsSpecified(nullable)
) {
override fun replaceAnnotations(newAnnotations: Annotations) = this
override fun makeNullableAsSpecified(newNullability: Boolean) = this
override fun makeNullableAsSpecified(newNullability: Boolean) = TypeTemplate(typeVariable, coroutineInferenceData, newNullability)
override val delegate: SimpleType
get() = upperBound